001package org.slf4j.spi;
002
003import java.util.function.Supplier;
004
005import org.slf4j.Logger;
006import org.slf4j.Marker;
007import org.slf4j.event.Level;
008
009/**
010 * <p>A no-operation implementation of {@link LoggingEventBuilder}.</p>
011 * <p></p>
012 * <p>As the name indicates, the methods in this class do nothing. In case a return value is expected, a singleton,
013 * i.e. the unique instance of this class, is returned.
014 * </p>
015 * <p></p>
016 * <p>Note that the default implementations of {@link Logger#atTrace()}, {@link Logger#atDebug()} , {@link Logger#atInfo()},
017 * {@link Logger#atWarn()}  and {@link Logger#atError()}, return an instance of {@link NOPLoggingEventBuilder}
018 * when the relevant level is disabled for current logger. This is the core optimization in the SLF4J fluent API.</p>
019 *
020 * @author Ceki G&uuml;lc&uuml;
021 * @since 2.0.0
022 *
023 */
024public class NOPLoggingEventBuilder implements LoggingEventBuilder {
025
026    static final NOPLoggingEventBuilder SINGLETON = new NOPLoggingEventBuilder();
027
028    private NOPLoggingEventBuilder() {
029    }
030
031    /**
032     * <p>Returns the singleton instance of this class.
033     * Used by {@link org.slf4j.Logger#makeLoggingEventBuilder(Level) makeLoggingEventBuilder(Level)}.</p>
034     *
035     * @return the singleton instance of this class
036     */
037    public static LoggingEventBuilder singleton() {
038        return SINGLETON;
039    }
040
041    /**
042     * <p>NOP implementation that does nothing.</p>
043     * 
044     * @param marker a Marker instance to add.
045     * @return
046     */
047    @Override
048    public LoggingEventBuilder addMarker(Marker marker) {
049        return this;
050    }
051
052    /**
053     * <p>NOP implementation that does nothing.</p>
054     *
055     * @param p 
056     * @return a LoggingEventBuilder, usually <b>this</b>.
057     * @since  2.1.0
058     */
059    @Override
060    public LoggingEventBuilder addArgument(Object p) {
061        return this;
062    }
063
064    /**
065     * <p>NOP implementation that does nothing and thus skips calling get() call on the object supplier.</p>
066     *
067     * @param objectSupplier
068     * @return a LoggingEventBuilder, usually <b>this</b>.
069     * @since  2.1.0
070     */
071    @Override
072    public LoggingEventBuilder addArgument(Supplier<?> objectSupplier) {
073        return this;
074    }
075
076    /**
077     * <p>NOP implementation that does nothing and thus skips calling get() call on the object supplier.</p>
078     *
079     * @param objectSupplier 
080     * @return a LoggingEventBuilder, usually <b>this</b>.
081     * @since  2.1.0
082     */
083    @Override
084    public LoggingEventBuilder arg(Supplier<?> objectSupplier) {
085        return this;
086    }
087
088    
089    /**
090     * <p>NOP implementation that does nothing and thus skips the type cast.</p>
091     *
092     * @param b a value of type <code>boolean</code> value to add.
093     * @return a LoggingEventBuilder, usually <b>this</b>.
094     * @since  2.1.0
095     */
096    public LoggingEventBuilder arg(boolean b) {
097        return this;
098    }
099
100    /**
101     * <p>NOP implementation that does nothing and thus skips the type cast.</p>
102     *
103     * @param c a value of type <code>char</code> value to add.
104     * @return a LoggingEventBuilder, usually <b>this</b>.
105     * @since  2.1.0
106     */
107    @Override
108    public LoggingEventBuilder arg(char c) {
109        return this;
110    }
111
112    /**
113     * <p>NOP implementation that does nothing and thus skips the type cast.</p>
114     *
115     * @param b a value of type <code>byte</code> value to add.
116     * @return a LoggingEventBuilder, usually <b>this</b>.
117     * @since  2.1.0
118     */
119    @Override
120    public LoggingEventBuilder arg(byte b) {
121        return this;
122    }
123
124    /**
125     * <p>NOP implementation that does nothing and thus skips the type cast.</p>
126     *
127     * @param s a value of type <code>short</code> value to add.
128     * @return a LoggingEventBuilder, usually <b>this</b>.
129     * @since  2.1.0
130     */
131    public LoggingEventBuilder arg(short s) {
132        return this;
133    }
134
135    /**
136     * <p>NOP implementation that does nothing and thus skips the type cast.</p>
137     *
138     * @param i a value of type <code>int</code> value to add.
139     * @return a LoggingEventBuilder, usually <b>this</b>.
140     * @since  2.1.0
141     */
142    @Override
143    public LoggingEventBuilder arg(int i) {
144        return this;
145    }
146
147    /**
148     * <p>NOP implementation that does nothing and thus skips the type cast.</p>
149     *
150     * @param l a value of type <code>long</code> value to add.
151     * @return a LoggingEventBuilder, usually <b>this</b>.
152     * @since  2.1.0
153     */
154    @Override
155    public LoggingEventBuilder arg(long l) {
156        return this;
157    }
158
159    /**
160     * <p>NOP implementation that does nothing and thus skips the type cast.</p>
161     *
162     * @param f a value of type <code>float</code> value to add.
163     * @return a LoggingEventBuilder, usually <b>this</b>.
164     * @since  2.1.0
165     */
166    @Override
167    public LoggingEventBuilder arg(float f) {
168        return this;
169    }
170
171    /**
172     * <p>NOP implementation that does nothing and thus skips the type cast.</p>
173     *
174     * @param d a value of type <code>float</code> value to add.
175     * @return a LoggingEventBuilder, usually <b>this</b>.
176     * @since  2.1.0
177     */
178    @Override
179    public LoggingEventBuilder arg(double d) {
180        return this;
181    }
182
183    /**
184     * NOP implementation that does nothing.
185     *
186     * @param key the key of the key value pair.
187     * @param value the value of the key value pair.
188     * @return a LoggingEventBuilder, usually <b>this</b>.
189     */
190    @Override
191    public LoggingEventBuilder addKeyValue(String key, Object value) {
192        return this;
193    }
194
195    /**
196     * NOP implementation that doesnothing.
197     *
198     * @param key the key of the key value pair.
199     * @param value the value of the key value pair.
200     * @return a LoggingEventBuilder, usually <b>this</b>.
201     */
202    @Override
203    public LoggingEventBuilder kv(String key, Object value) {
204        return this;
205    }
206
207    /**
208     * NOP implementation that doesnothing.
209     *
210     * @param key the key of the key value pair.
211     * @param value a supplier of a value for the key value pair.
212     * @return a LoggingEventBuilder, usually <b>this</b>.
213     */
214    @Override
215    public LoggingEventBuilder addKeyValue(String key, Supplier<Object> value) {
216        return this;
217    }
218
219    /**
220     * NOP implementation that doesnothing.
221     *
222     * @param key the key of the key value pair.
223     * @param value a supplier of a value for the key value pair.
224     * @return a LoggingEventBuilder, usually <b>this</b>.
225     */
226    @Override
227    public LoggingEventBuilder kv(String key, Supplier<Object> value) {
228        return this;
229    }
230
231    /**
232     * NOP implementation that does nothing.
233     *
234     * @param key the key of the key value pair.
235     * @param b the value of type <code>boolean</code> of the key value pair.
236     * @return a LoggingEventBuilder, usually <b>this</b>.
237     */
238    @Override
239    public LoggingEventBuilder kv(String key, boolean b) {
240        return this;
241    }
242
243    /**
244     * NOP implementation that does nothing.
245     *
246     * @param key the key of the key value pair.
247     * @param c the value of type <code>char</code> of the key value pair.
248     * @return
249     */
250    @Override
251    public LoggingEventBuilder kv(String key, char c) {
252        return this;
253    }
254
255    /**
256     * NOP implementation that does nothing.
257     *
258     * @param key the key of the key value pair.
259     * @param b the value of type <code>byte</code> of the key value pair.
260     * @return
261     */
262    @Override
263    public LoggingEventBuilder kv(String key, byte b) {
264        return this;
265    }
266
267    /**
268     * NOP implementation that does nothing.
269     *
270     * @param key the key of the key value pair.
271     * @param s the value of type <code>short</code> of the key value pair.
272     * @return
273     */
274    @Override
275    public LoggingEventBuilder kv(String key, short s) {
276        return this;
277    }
278
279    /**
280     * NOP implementation that does nothing.
281     *
282     * @param key the key of the key value pair.
283     * @param i the value of type <code>int</code> of the key value pair.
284     * @return
285     */
286    @Override
287    public LoggingEventBuilder kv(String key, int i) {
288        return this;
289    }
290
291    /**
292     * NOP implementation that does nothing.
293     *
294     * @param key the key of the key value pair.
295     * @param l the value of type <code>long</code> of the key value pair.
296     * @return
297     */
298    @Override
299    public LoggingEventBuilder kv(String key, long l) {
300        return this;
301    }
302
303
304    /**
305     * NOP implementation that does nothing.
306     *
307     * @param key the key of the key value pair.
308     * @param f the value of type <code>float</code> of the key value pair.
309     * @return
310     */
311    @Override
312    public LoggingEventBuilder kv(String key, float f) {
313        return this;
314    }
315
316    /**
317     * NOP implementation that does nothing.
318     *
319     * @param key the key of the key value pair.
320     * @param d the value of type <code>double</code> of the key value pair.
321     * @return
322     */
323    @Override
324    public LoggingEventBuilder kv(String key, double d) {
325        return this;
326    }
327
328    /**
329     * NOP implementation that does nothing.
330     *
331     * @param cause a throwable
332     * @return
333     */
334    @Override
335    public LoggingEventBuilder setCause(Throwable cause) {
336        return this;
337    }
338
339    /**
340     *
341     */
342    @Override
343    public void log() {
344    }
345
346    /**
347     * NOP implementation that does nothing.
348     *
349     * @param message the message of the event
350     * @return
351     */
352    @Override
353    public LoggingEventBuilder setMessage(String message) {
354        return this;
355    }
356
357    /**
358     * NOP implementation that does nothing.
359     *
360     * @param messageSupplier supplies a String to be used as the message for the event
361     * @return
362     */
363    @Override
364    public LoggingEventBuilder setMessage(Supplier<String> messageSupplier) {
365        return this;
366    }
367
368    /**
369     * NOP implementation that does nothing.
370     *
371     * @param message the message to log
372     */
373    @Override
374    public void log(String message) {
375    }
376
377    /**
378     * NOP implementation that does nothing.
379     *
380     * @param messageSupplier a Supplier returning a message of type String
381     */
382    @Override
383    public void log(Supplier<String> messageSupplier) {
384    }
385
386    /**
387     * NOP implementation that does nothing.
388     *
389     * @param message the message to log
390     * @param arg an argument to be used with the message to log
391     */
392    @Override
393    public void log(String message, Object arg) {
394    }
395
396    /**
397     * NOP implementation that does nothing.
398     *
399     * @param message the message to log
400     * @param arg0 first argument to be used with the message to log
401     * @param arg1 second argument to be used with the message to log
402     */
403    @Override
404    public void log(String message, Object arg0, Object arg1) {
405    }
406
407    /**
408     * NOP implementation that does nothing.
409     *
410     * @param message the message to log
411     * @param args a list (actually an array) of arguments to be used with the message to log
412     */
413    @Override
414    public void log(String message, Object... args) {
415    }
416}