001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache license, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the license for the specific language governing permissions and
015 * limitations under the license.
016 */
017package org.apache.logging.log4j.spi;
018
019import java.io.Serializable;
020
021import org.apache.logging.log4j.Level;
022import org.apache.logging.log4j.Marker;
023import org.apache.logging.log4j.MarkerManager;
024import org.apache.logging.log4j.message.Message;
025import org.apache.logging.log4j.message.MessageFactory;
026import org.apache.logging.log4j.message.ParameterizedMessageFactory;
027import org.apache.logging.log4j.message.StringFormattedMessage;
028import org.apache.logging.log4j.status.StatusLogger;
029import org.apache.logging.log4j.util.LambdaUtil;
030import org.apache.logging.log4j.util.MessageSupplier;
031import org.apache.logging.log4j.util.Supplier;
032
033/**
034 * Base implementation of a Logger. It is highly recommended that any Logger implementation extend this class.
035 */
036public abstract class AbstractLogger implements ExtendedLogger, Serializable {
037
038    /**
039     * Marker for flow tracing.
040     */
041    public static final Marker FLOW_MARKER = MarkerManager.getMarker("FLOW");
042
043    /**
044     * Marker for method entry tracing.
045     */
046    public static final Marker ENTRY_MARKER = MarkerManager.getMarker("ENTRY").setParents(FLOW_MARKER);
047
048    /**
049     * Marker for method exit tracing.
050     */
051    public static final Marker EXIT_MARKER = MarkerManager.getMarker("EXIT").setParents(FLOW_MARKER);
052
053    /**
054     * Marker for exception tracing.
055     */
056    public static final Marker EXCEPTION_MARKER = MarkerManager.getMarker("EXCEPTION");
057
058    /**
059     * Marker for throwing exceptions.
060     */
061    public static final Marker THROWING_MARKER = MarkerManager.getMarker("THROWING").setParents(EXCEPTION_MARKER);
062
063    /**
064     * Marker for catching exceptions.
065     */
066    public static final Marker CATCHING_MARKER = MarkerManager.getMarker("CATCHING").setParents(EXCEPTION_MARKER);
067
068    /**
069     * The default MessageFactory class.
070     */
071    public static final Class<? extends MessageFactory> DEFAULT_MESSAGE_FACTORY_CLASS =
072            ParameterizedMessageFactory.class;
073
074    private static final long serialVersionUID = 2L;
075
076    private static final String FQCN = AbstractLogger.class.getName();
077    private static final String THROWING = "throwing";
078    private static final String CATCHING = "catching";
079
080    private final String name;
081    private final MessageFactory messageFactory;
082
083    /**
084     * Creates a new logger named after this class (or subclass).
085     */
086    public AbstractLogger() {
087        this.name = getClass().getName();
088        this.messageFactory = createDefaultMessageFactory();
089    }
090
091    /**
092     * Creates a new named logger.
093     *
094     * @param name the logger name
095     */
096    public AbstractLogger(final String name) {
097        this.name = name;
098        this.messageFactory = createDefaultMessageFactory();
099    }
100
101    /**
102     * Creates a new named logger with a particular {@link MessageFactory}.
103     *
104     * @param name the logger name
105     * @param messageFactory the message factory, if null then use the default message factory.
106     */
107    public AbstractLogger(final String name, final MessageFactory messageFactory) {
108        this.name = name;
109        this.messageFactory = messageFactory == null ? createDefaultMessageFactory() : messageFactory;
110    }
111
112    /**
113     * Checks that the message factory a logger was created with is the same as the given messageFactory. If they are
114     * different log a warning to the {@linkplain StatusLogger}. A null MessageFactory translates to the default
115     * MessageFactory {@link #DEFAULT_MESSAGE_FACTORY_CLASS}.
116     *
117     * @param logger The logger to check
118     * @param messageFactory The message factory to check.
119     */
120    public static void checkMessageFactory(final ExtendedLogger logger, final MessageFactory messageFactory) {
121        final String name = logger.getName();
122        final MessageFactory loggerMessageFactory = logger.getMessageFactory();
123        if (messageFactory != null && !loggerMessageFactory.equals(messageFactory)) {
124            StatusLogger.getLogger().warn(
125                    "The Logger {} was created with the message factory {} and is now requested with the "
126                            + "message factory {}, which may create log events with unexpected formatting.", name,
127                    loggerMessageFactory, messageFactory);
128        } else if (messageFactory == null && !loggerMessageFactory.getClass().equals(DEFAULT_MESSAGE_FACTORY_CLASS)) {
129            StatusLogger
130                    .getLogger()
131                    .warn("The Logger {} was created with the message factory {} and is now requested with a null "
132                            + "message factory (defaults to {}), which may create log events with unexpected "
133                            + "formatting.",
134                            name, loggerMessageFactory, DEFAULT_MESSAGE_FACTORY_CLASS.getName());
135        }
136    }
137
138    @Override
139    public void catching(final Level level, final Throwable t) {
140        catching(FQCN, level, t);
141    }
142
143    /**
144     * Logs a Throwable that has been caught with location information.
145     *
146     * @param fqcn The fully qualified class name of the <b>caller</b>.
147     * @param level The logging level.
148     * @param t The Throwable.
149     */
150    protected void catching(final String fqcn, final Level level, final Throwable t) {
151        if (isEnabled(level, CATCHING_MARKER, (Object) null, null)) {
152            logMessage(fqcn, level, CATCHING_MARKER, catchingMsg(t), t);
153        }
154    }
155
156    @Override
157    public void catching(final Throwable t) {
158        if (isEnabled(Level.ERROR, CATCHING_MARKER, (Object) null, null)) {
159            logMessage(FQCN, Level.ERROR, CATCHING_MARKER, catchingMsg(t), t);
160        }
161    }
162
163    protected Message catchingMsg(final Throwable t) {
164        return messageFactory.newMessage(CATCHING);
165    }
166
167    private MessageFactory createDefaultMessageFactory() {
168        try {
169            return DEFAULT_MESSAGE_FACTORY_CLASS.newInstance();
170        } catch (final InstantiationException e) {
171            throw new IllegalStateException(e);
172        } catch (final IllegalAccessException e) {
173            throw new IllegalStateException(e);
174        }
175    }
176
177    @Override
178    public void debug(final Marker marker, final Message msg) {
179        logIfEnabled(FQCN, Level.DEBUG, marker, msg, null);
180    }
181
182    @Override
183    public void debug(final Marker marker, final Message msg, final Throwable t) {
184        logIfEnabled(FQCN, Level.DEBUG, marker, msg, t);
185    }
186
187    @Override
188    public void debug(final Marker marker, final Object message) {
189        logIfEnabled(FQCN, Level.DEBUG, marker, message, null);
190    }
191
192    @Override
193    public void debug(final Marker marker, final Object message, final Throwable t) {
194        logIfEnabled(FQCN, Level.DEBUG, marker, message, t);
195    }
196
197    @Override
198    public void debug(final Marker marker, final String message) {
199        logIfEnabled(FQCN, Level.DEBUG, marker, message, (Throwable) null);
200    }
201
202    @Override
203    public void debug(final Marker marker, final String message, final Object... params) {
204        logIfEnabled(FQCN, Level.DEBUG, marker, message, params);
205    }
206
207    @Override
208    public void debug(final Marker marker, final String message, final Throwable t) {
209        logIfEnabled(FQCN, Level.DEBUG, marker, message, t);
210    }
211
212    @Override
213    public void debug(final Message msg) {
214        logIfEnabled(FQCN, Level.DEBUG, null, msg, null);
215    }
216
217    @Override
218    public void debug(final Message msg, final Throwable t) {
219        logIfEnabled(FQCN, Level.DEBUG, null, msg, t);
220    }
221
222    @Override
223    public void debug(final Object message) {
224        logIfEnabled(FQCN, Level.DEBUG, null, message, null);
225    }
226
227    @Override
228    public void debug(final Object message, final Throwable t) {
229        logIfEnabled(FQCN, Level.DEBUG, null, message, t);
230    }
231
232    @Override
233    public void debug(final String message) {
234        logIfEnabled(FQCN, Level.DEBUG, null, message, (Throwable) null);
235    }
236
237    @Override
238    public void debug(final String message, final Object... params) {
239        logIfEnabled(FQCN, Level.DEBUG, null, message, params);
240    }
241
242    @Override
243    public void debug(final String message, final Throwable t) {
244        logIfEnabled(FQCN, Level.DEBUG, null, message, t);
245    }
246
247    @Override
248    public void debug(final Supplier<?> msgSupplier) {
249        logIfEnabled(FQCN, Level.DEBUG, null, msgSupplier, (Throwable) null);
250    }
251
252    @Override
253    public void debug(final Supplier<?> msgSupplier, final Throwable t) {
254        logIfEnabled(FQCN, Level.DEBUG, null, msgSupplier, t);
255    }
256
257    @Override
258    public void debug(final Marker marker, final Supplier<?> msgSupplier) {
259        logIfEnabled(FQCN, Level.DEBUG, marker, msgSupplier, (Throwable) null);
260    }
261
262    @Override
263    public void debug(final Marker marker, final String message, final Supplier<?>... paramSuppliers) {
264        logIfEnabled(FQCN, Level.DEBUG, marker, message, paramSuppliers);
265    }
266
267    @Override
268    public void debug(final Marker marker, final Supplier<?> msgSupplier, final Throwable t) {
269        logIfEnabled(FQCN, Level.DEBUG, marker, msgSupplier, t);
270    }
271
272    @Override
273    public void debug(final String message, final Supplier<?>... paramSuppliers) {
274        logIfEnabled(FQCN, Level.DEBUG, null, message, paramSuppliers);
275    }
276
277    @Override
278    public void debug(final Marker marker, final MessageSupplier msgSupplier) {
279        logIfEnabled(FQCN, Level.DEBUG, marker, msgSupplier, (Throwable) null);
280    }
281
282    @Override
283    public void debug(final Marker marker, final MessageSupplier msgSupplier, final Throwable t) {
284        logIfEnabled(FQCN, Level.DEBUG, marker, msgSupplier, t);
285    }
286
287    @Override
288    public void debug(final MessageSupplier msgSupplier) {
289        logIfEnabled(FQCN, Level.DEBUG, null, msgSupplier, (Throwable) null);
290    }
291
292    @Override
293    public void debug(final MessageSupplier msgSupplier, final Throwable t) {
294        logIfEnabled(FQCN, Level.DEBUG, null, msgSupplier, t);
295    }
296
297    @Override
298    public void entry() {
299        entry(FQCN);
300    }
301
302    @Override
303    public void entry(final Object... params) {
304        entry(FQCN, params);
305    }
306
307    /**
308     * Logs entry to a method with location information.
309     *
310     * @param fqcn The fully qualified class name of the <b>caller</b>.
311     * @param params The parameters to the method.
312     */
313    protected void entry(final String fqcn, final Object... params) {
314        if (isEnabled(Level.TRACE, ENTRY_MARKER, (Object) null, null)) {
315            logIfEnabled(fqcn, Level.TRACE, ENTRY_MARKER, entryMsg(params.length, params), null);
316        }
317    }
318
319    protected Message entryMsg(final int count, final Object... params) {
320        if (count == 0) {
321            return messageFactory.newMessage("entry");
322        }
323        final StringBuilder sb = new StringBuilder("entry params(");
324        for (int i = 0; i < params.length; i++) {
325            Object parm = params[i];
326            sb.append(parm != null ? parm.toString() : "null");
327            if (i + 1 < params.length) {
328                sb.append(", ");
329            }
330        }
331        sb.append(')');
332        return messageFactory.newMessage(sb.toString());
333    }
334
335    @Override
336    public void error(final Marker marker, final Message msg) {
337        logIfEnabled(FQCN, Level.ERROR, marker, msg, null);
338    }
339
340    @Override
341    public void error(final Marker marker, final Message msg, final Throwable t) {
342        logIfEnabled(FQCN, Level.ERROR, marker, msg, t);
343    }
344
345    @Override
346    public void error(final Marker marker, final Object message) {
347        logIfEnabled(FQCN, Level.ERROR, marker, message, null);
348    }
349
350    @Override
351    public void error(final Marker marker, final Object message, final Throwable t) {
352        logIfEnabled(FQCN, Level.ERROR, marker, message, t);
353    }
354
355    @Override
356    public void error(final Marker marker, final String message) {
357        logIfEnabled(FQCN, Level.ERROR, marker, message, (Throwable) null);
358    }
359
360    @Override
361    public void error(final Marker marker, final String message, final Object... params) {
362        logIfEnabled(FQCN, Level.ERROR, marker, message, params);
363    }
364
365    @Override
366    public void error(final Marker marker, final String message, final Throwable t) {
367        logIfEnabled(FQCN, Level.ERROR, marker, message, t);
368    }
369
370    @Override
371    public void error(final Message msg) {
372        logIfEnabled(FQCN, Level.ERROR, null, msg, null);
373    }
374
375    @Override
376    public void error(final Message msg, final Throwable t) {
377        logIfEnabled(FQCN, Level.ERROR, null, msg, t);
378    }
379
380    @Override
381    public void error(final Object message) {
382        logIfEnabled(FQCN, Level.ERROR, null, message, null);
383    }
384
385    @Override
386    public void error(final Object message, final Throwable t) {
387        logIfEnabled(FQCN, Level.ERROR, null, message, t);
388    }
389
390    @Override
391    public void error(final String message) {
392        logIfEnabled(FQCN, Level.ERROR, null, message, (Throwable) null);
393    }
394
395    @Override
396    public void error(final String message, final Object... params) {
397        logIfEnabled(FQCN, Level.ERROR, null, message, params);
398    }
399
400    @Override
401    public void error(final String message, final Throwable t) {
402        logIfEnabled(FQCN, Level.ERROR, null, message, t);
403    }
404
405    @Override
406    public void error(final Supplier<?> msgSupplier) {
407        logIfEnabled(FQCN, Level.ERROR, null, msgSupplier, (Throwable) null);
408    }
409
410    @Override
411    public void error(final Supplier<?> msgSupplier, final Throwable t) {
412        logIfEnabled(FQCN, Level.ERROR, null, msgSupplier, t);
413    }
414
415    @Override
416    public void error(final Marker marker, final Supplier<?> msgSupplier) {
417        logIfEnabled(FQCN, Level.ERROR, marker, msgSupplier, (Throwable) null);
418    }
419
420    @Override
421    public void error(final Marker marker, final String message, final Supplier<?>... paramSuppliers) {
422        logIfEnabled(FQCN, Level.ERROR, marker, message, paramSuppliers);
423    }
424
425    @Override
426    public void error(final Marker marker, final Supplier<?> msgSupplier, final Throwable t) {
427        logIfEnabled(FQCN, Level.ERROR, marker, msgSupplier, t);
428    }
429
430    @Override
431    public void error(final String message, final Supplier<?>... paramSuppliers) {
432        logIfEnabled(FQCN, Level.ERROR, null, message, paramSuppliers);
433    }
434
435    @Override
436    public void error(final Marker marker, final MessageSupplier msgSupplier) {
437        logIfEnabled(FQCN, Level.ERROR, marker, msgSupplier, (Throwable) null);
438    }
439
440    @Override
441    public void error(final Marker marker, final MessageSupplier msgSupplier, final Throwable t) {
442        logIfEnabled(FQCN, Level.ERROR, marker, msgSupplier, t);
443    }
444
445    @Override
446    public void error(final MessageSupplier msgSupplier) {
447        logIfEnabled(FQCN, Level.ERROR, null, msgSupplier, (Throwable) null);
448    }
449
450    @Override
451    public void error(final MessageSupplier msgSupplier, final Throwable t) {
452        logIfEnabled(FQCN, Level.ERROR, null, msgSupplier, t);
453    }
454
455    @Override
456    public void exit() {
457        exit(FQCN, null);
458    }
459
460    @Override
461    public <R> R exit(final R result) {
462        return exit(FQCN, result);
463    }
464
465    /**
466     * Logs exiting from a method with the result and location information.
467     *
468     * @param fqcn The fully qualified class name of the <b>caller</b>.
469     * @param <R> The type of the parameter and object being returned.
470     * @param result The result being returned from the method call.
471     * @return the return value passed to this method.
472     */
473    protected <R> R exit(final String fqcn, final R result) {
474        if (isEnabled(Level.TRACE, EXIT_MARKER, (Object) null, null)) {
475            logIfEnabled(fqcn, Level.TRACE, EXIT_MARKER, exitMsg(result), null);
476        }
477        return result;
478    }
479
480    protected Message exitMsg(final Object result) {
481        if (result == null) {
482            return messageFactory.newMessage("exit");
483        }
484        return messageFactory.newMessage("exit with(" + result + ')');
485    }
486
487    @Override
488    public void fatal(final Marker marker, final Message msg) {
489        logIfEnabled(FQCN, Level.FATAL, marker, msg, null);
490    }
491
492    @Override
493    public void fatal(final Marker marker, final Message msg, final Throwable t) {
494        logIfEnabled(FQCN, Level.FATAL, marker, msg, t);
495    }
496
497    @Override
498    public void fatal(final Marker marker, final Object message) {
499        logIfEnabled(FQCN, Level.FATAL, marker, message, null);
500    }
501
502    @Override
503    public void fatal(final Marker marker, final Object message, final Throwable t) {
504        logIfEnabled(FQCN, Level.FATAL, marker, message, t);
505    }
506
507    @Override
508    public void fatal(final Marker marker, final String message) {
509        logIfEnabled(FQCN, Level.FATAL, marker, message, (Throwable) null);
510    }
511
512    @Override
513    public void fatal(final Marker marker, final String message, final Object... params) {
514        logIfEnabled(FQCN, Level.FATAL, marker, message, params);
515    }
516
517    @Override
518    public void fatal(final Marker marker, final String message, final Throwable t) {
519        logIfEnabled(FQCN, Level.FATAL, marker, message, t);
520    }
521
522    @Override
523    public void fatal(final Message msg) {
524        logIfEnabled(FQCN, Level.FATAL, null, msg, null);
525    }
526
527    @Override
528    public void fatal(final Message msg, final Throwable t) {
529        logIfEnabled(FQCN, Level.FATAL, null, msg, t);
530    }
531
532    @Override
533    public void fatal(final Object message) {
534        logIfEnabled(FQCN, Level.FATAL, null, message, null);
535    }
536
537    @Override
538    public void fatal(final Object message, final Throwable t) {
539        logIfEnabled(FQCN, Level.FATAL, null, message, t);
540    }
541
542    @Override
543    public void fatal(final String message) {
544        logIfEnabled(FQCN, Level.FATAL, null, message, (Throwable) null);
545    }
546
547    @Override
548    public void fatal(final String message, final Object... params) {
549        logIfEnabled(FQCN, Level.FATAL, null, message, params);
550    }
551
552    @Override
553    public void fatal(final String message, final Throwable t) {
554        logIfEnabled(FQCN, Level.FATAL, null, message, t);
555    }
556
557    @Override
558    public void fatal(final Supplier<?> msgSupplier) {
559        logIfEnabled(FQCN, Level.FATAL, null, msgSupplier, (Throwable) null);
560    }
561
562    @Override
563    public void fatal(final Supplier<?> msgSupplier, final Throwable t) {
564        logIfEnabled(FQCN, Level.FATAL, null, msgSupplier, t);
565    }
566
567    @Override
568    public void fatal(final Marker marker, final Supplier<?> msgSupplier) {
569        logIfEnabled(FQCN, Level.FATAL, marker, msgSupplier, (Throwable) null);
570    }
571
572    @Override
573    public void fatal(final Marker marker, final String message, final Supplier<?>... paramSuppliers) {
574        logIfEnabled(FQCN, Level.FATAL, marker, message, paramSuppliers);
575    }
576
577    @Override
578    public void fatal(final Marker marker, final Supplier<?> msgSupplier, final Throwable t) {
579        logIfEnabled(FQCN, Level.FATAL, marker, msgSupplier, t);
580    }
581
582    @Override
583    public void fatal(final String message, final Supplier<?>... paramSuppliers) {
584        logIfEnabled(FQCN, Level.FATAL, null, message, paramSuppliers);
585    }
586
587    @Override
588    public void fatal(final Marker marker, final MessageSupplier msgSupplier) {
589        logIfEnabled(FQCN, Level.FATAL, marker, msgSupplier, (Throwable) null);
590    }
591
592    @Override
593    public void fatal(final Marker marker, final MessageSupplier msgSupplier, final Throwable t) {
594        logIfEnabled(FQCN, Level.FATAL, marker, msgSupplier, t);
595    }
596
597    @Override
598    public void fatal(final MessageSupplier msgSupplier) {
599        logIfEnabled(FQCN, Level.FATAL, null, msgSupplier, (Throwable) null);
600    }
601
602    @Override
603    public void fatal(final MessageSupplier msgSupplier, final Throwable t) {
604        logIfEnabled(FQCN, Level.FATAL, null, msgSupplier, t);
605    }
606
607    @Override
608    public MessageFactory getMessageFactory() {
609        return messageFactory;
610    }
611
612    @Override
613    public String getName() {
614        return name;
615    }
616
617    @Override
618    public void info(final Marker marker, final Message msg) {
619        logIfEnabled(FQCN, Level.INFO, marker, msg, null);
620    }
621
622    @Override
623    public void info(final Marker marker, final Message msg, final Throwable t) {
624        logIfEnabled(FQCN, Level.INFO, marker, msg, t);
625    }
626
627    @Override
628    public void info(final Marker marker, final Object message) {
629        logIfEnabled(FQCN, Level.INFO, marker, message, null);
630    }
631
632    @Override
633    public void info(final Marker marker, final Object message, final Throwable t) {
634        logIfEnabled(FQCN, Level.INFO, marker, message, t);
635    }
636
637    @Override
638    public void info(final Marker marker, final String message) {
639        logIfEnabled(FQCN, Level.INFO, marker, message, (Throwable) null);
640    }
641
642    @Override
643    public void info(final Marker marker, final String message, final Object... params) {
644        logIfEnabled(FQCN, Level.INFO, marker, message, params);
645    }
646
647    @Override
648    public void info(final Marker marker, final String message, final Throwable t) {
649        logIfEnabled(FQCN, Level.INFO, marker, message, t);
650    }
651
652    @Override
653    public void info(final Message msg) {
654        logIfEnabled(FQCN, Level.INFO, null, msg, null);
655    }
656
657    @Override
658    public void info(final Message msg, final Throwable t) {
659        logIfEnabled(FQCN, Level.INFO, null, msg, t);
660    }
661
662    @Override
663    public void info(final Object message) {
664        logIfEnabled(FQCN, Level.INFO, null, message, null);
665    }
666
667    @Override
668    public void info(final Object message, final Throwable t) {
669        logIfEnabled(FQCN, Level.INFO, null, message, t);
670    }
671
672    @Override
673    public void info(final String message) {
674        logIfEnabled(FQCN, Level.INFO, null, message, (Throwable) null);
675    }
676
677    @Override
678    public void info(final String message, final Object... params) {
679        logIfEnabled(FQCN, Level.INFO, null, message, params);
680    }
681
682    @Override
683    public void info(final String message, final Throwable t) {
684        logIfEnabled(FQCN, Level.INFO, null, message, t);
685    }
686
687    @Override
688    public void info(final Supplier<?> msgSupplier) {
689        logIfEnabled(FQCN, Level.INFO, null, msgSupplier, (Throwable) null);
690    }
691
692    @Override
693    public void info(final Supplier<?> msgSupplier, final Throwable t) {
694        logIfEnabled(FQCN, Level.INFO, null, msgSupplier, t);
695    }
696
697    @Override
698    public void info(final Marker marker, final Supplier<?> msgSupplier) {
699        logIfEnabled(FQCN, Level.INFO, marker, msgSupplier, (Throwable) null);
700    }
701
702    @Override
703    public void info(final Marker marker, final String message, final Supplier<?>... paramSuppliers) {
704        logIfEnabled(FQCN, Level.INFO, marker, message, paramSuppliers);
705    }
706
707    @Override
708    public void info(final Marker marker, final Supplier<?> msgSupplier, final Throwable t) {
709        logIfEnabled(FQCN, Level.INFO, marker, msgSupplier, t);
710    }
711
712    @Override
713    public void info(final String message, final Supplier<?>... paramSuppliers) {
714        logIfEnabled(FQCN, Level.INFO, null, message, paramSuppliers);
715    }
716
717    @Override
718    public void info(final Marker marker, final MessageSupplier msgSupplier) {
719        logIfEnabled(FQCN, Level.INFO, marker, msgSupplier, (Throwable) null);
720    }
721
722    @Override
723    public void info(final Marker marker, final MessageSupplier msgSupplier, final Throwable t) {
724        logIfEnabled(FQCN, Level.INFO, marker, msgSupplier, t);
725    }
726
727    @Override
728    public void info(final MessageSupplier msgSupplier) {
729        logIfEnabled(FQCN, Level.INFO, null, msgSupplier, (Throwable) null);
730    }
731
732    @Override
733    public void info(final MessageSupplier msgSupplier, final Throwable t) {
734        logIfEnabled(FQCN, Level.INFO, null, msgSupplier, t);
735    }
736
737    @Override
738    public boolean isDebugEnabled() {
739        return isEnabled(Level.DEBUG, null, null);
740    }
741
742    @Override
743    public boolean isDebugEnabled(final Marker marker) {
744        return isEnabled(Level.DEBUG, marker, (Object) null, null);
745    }
746
747    @Override
748    public boolean isEnabled(final Level level) {
749        return isEnabled(level, null, (Object) null, null);
750    }
751
752    @Override
753    public boolean isEnabled(final Level level, final Marker marker) {
754        return isEnabled(level, marker, (Object) null, null);
755    }
756
757    @Override
758    public boolean isErrorEnabled() {
759        return isEnabled(Level.ERROR, null, (Object) null, null);
760    }
761
762    @Override
763    public boolean isErrorEnabled(final Marker marker) {
764        return isEnabled(Level.ERROR, marker, (Object) null, null);
765    }
766
767    @Override
768    public boolean isFatalEnabled() {
769        return isEnabled(Level.FATAL, null, (Object) null, null);
770    }
771
772    @Override
773    public boolean isFatalEnabled(final Marker marker) {
774        return isEnabled(Level.FATAL, marker, (Object) null, null);
775    }
776
777    @Override
778    public boolean isInfoEnabled() {
779        return isEnabled(Level.INFO, null, (Object) null, null);
780    }
781
782    @Override
783    public boolean isInfoEnabled(final Marker marker) {
784        return isEnabled(Level.INFO, marker, (Object) null, null);
785    }
786
787    @Override
788    public boolean isTraceEnabled() {
789        return isEnabled(Level.TRACE, null, (Object) null, null);
790    }
791
792    @Override
793    public boolean isTraceEnabled(final Marker marker) {
794        return isEnabled(Level.TRACE, marker, (Object) null, null);
795    }
796
797    @Override
798    public boolean isWarnEnabled() {
799        return isEnabled(Level.WARN, null, (Object) null, null);
800    }
801
802    @Override
803    public boolean isWarnEnabled(final Marker marker) {
804        return isEnabled(Level.WARN, marker, (Object) null, null);
805    }
806
807    @Override
808    public void log(final Level level, final Marker marker, final Message msg) {
809        logIfEnabled(FQCN, level, marker, msg, (Throwable) null);
810    }
811
812    @Override
813    public void log(final Level level, final Marker marker, final Message msg, final Throwable t) {
814        logIfEnabled(FQCN, level, marker, msg, t);
815    }
816
817    @Override
818    public void log(final Level level, final Marker marker, final Object message) {
819        logIfEnabled(FQCN, level, marker, message, (Throwable) null);
820    }
821
822    @Override
823    public void log(final Level level, final Marker marker, final Object message, final Throwable t) {
824        if (isEnabled(level, marker, message, t)) {
825            logMessage(FQCN, level, marker, message, t);
826        }
827    }
828
829    @Override
830    public void log(final Level level, final Marker marker, final String message) {
831        logIfEnabled(FQCN, level, marker, message, (Throwable) null);
832    }
833
834    @Override
835    public void log(final Level level, final Marker marker, final String message, final Object... params) {
836        logIfEnabled(FQCN, level, marker, message, params);
837    }
838
839    @Override
840    public void log(final Level level, final Marker marker, final String message, final Throwable t) {
841        logIfEnabled(FQCN, level, marker, message, t);
842    }
843
844    @Override
845    public void log(final Level level, final Message msg) {
846        logIfEnabled(FQCN, level, null, msg, null);
847    }
848
849    @Override
850    public void log(final Level level, final Message msg, final Throwable t) {
851        logIfEnabled(FQCN, level, null, msg, t);
852    }
853
854    @Override
855    public void log(final Level level, final Object message) {
856        logIfEnabled(FQCN, level, null, message, null);
857    }
858
859    @Override
860    public void log(final Level level, final Object message, final Throwable t) {
861        logIfEnabled(FQCN, level, null, message, t);
862    }
863
864    @Override
865    public void log(final Level level, final String message) {
866        logIfEnabled(FQCN, level, null, message, (Throwable) null);
867    }
868
869    @Override
870    public void log(final Level level, final String message, final Object... params) {
871        logIfEnabled(FQCN, level, null, message, params);
872    }
873
874    @Override
875    public void log(final Level level, final String message, final Throwable t) {
876        logIfEnabled(FQCN, level, null, message, t);
877    }
878
879    @Override
880    public void log(final Level level, final Supplier<?> msgSupplier) {
881        logIfEnabled(FQCN, level, null, msgSupplier, (Throwable) null);
882    }
883
884    @Override
885    public void log(final Level level, final Supplier<?> msgSupplier, final Throwable t) {
886        logIfEnabled(FQCN, level, null, msgSupplier, t);
887    }
888
889    @Override
890    public void log(final Level level, final Marker marker, final Supplier<?> msgSupplier) {
891        logIfEnabled(FQCN, level, marker, msgSupplier, (Throwable) null);
892    }
893
894    @Override
895    public void log(final Level level, final Marker marker, final String message, final Supplier<?>... paramSuppliers) {
896        logIfEnabled(FQCN, level, marker, message, paramSuppliers);
897    }
898
899    @Override
900    public void log(final Level level, final Marker marker, final Supplier<?> msgSupplier, final Throwable t) {
901        logIfEnabled(FQCN, level, marker, msgSupplier, t);
902    }
903
904    @Override
905    public void log(final Level level, final String message, final Supplier<?>... paramSuppliers) {
906        logIfEnabled(FQCN, level, null, message, paramSuppliers);
907    }
908
909    @Override
910    public void log(final Level level, final Marker marker, final MessageSupplier msgSupplier) {
911        logIfEnabled(FQCN, level, marker, msgSupplier, (Throwable) null);
912    }
913
914    @Override
915    public void log(final Level level, final Marker marker, final MessageSupplier msgSupplier, final Throwable t) {
916        logIfEnabled(FQCN, level, marker, msgSupplier, t);
917    }
918
919    @Override
920    public void log(final Level level, final MessageSupplier msgSupplier) {
921        logIfEnabled(FQCN, level, null, msgSupplier, (Throwable) null);
922    }
923
924    @Override
925    public void log(final Level level, final MessageSupplier msgSupplier, final Throwable t) {
926        logIfEnabled(FQCN, level, null, msgSupplier, t);
927    }
928
929    @Override
930    public void logIfEnabled(final String fqcn, final Level level, final Marker marker, final Message msg,
931            final Throwable t) {
932        if (isEnabled(level, marker, msg, t)) {
933            logMessage(fqcn, level, marker, msg, t);
934        }
935    }
936
937    @Override
938    public void logIfEnabled(final String fqcn, final Level level, final Marker marker,
939            final MessageSupplier msgSupplier, final Throwable t) {
940        if (isEnabled(level, marker, msgSupplier, t)) {
941            logMessage(fqcn, level, marker, msgSupplier, t);
942        }
943    }
944
945    @Override
946    public void logIfEnabled(final String fqcn, final Level level, final Marker marker, final Object message,
947            final Throwable t) {
948        if (isEnabled(level, marker, message, t)) {
949            logMessage(fqcn, level, marker, message, t);
950        }
951    }
952
953    @Override
954    public void logIfEnabled(final String fqcn, final Level level, final Marker marker, final Supplier<?> msgSupplier,
955            final Throwable t) {
956        if (isEnabled(level, marker, msgSupplier, t)) {
957            logMessage(fqcn, level, marker, msgSupplier, t);
958        }
959    }
960
961    @Override
962    public void logIfEnabled(final String fqcn, final Level level, final Marker marker, final String message) {
963        if (isEnabled(level, marker, message)) {
964            logMessage(fqcn, level, marker, message);
965        }
966    }
967
968    @Override
969    public void logIfEnabled(final String fqcn, final Level level, final Marker marker, final String message,
970            final Supplier<?>... paramSuppliers) {
971        if (isEnabled(level, marker, message)) {
972            logMessage(fqcn, level, marker, message, paramSuppliers);
973        }
974    }
975
976    @Override
977    public void logIfEnabled(final String fqcn, final Level level, final Marker marker, final String message,
978            final Object... params) {
979        if (isEnabled(level, marker, message, params)) {
980            logMessage(fqcn, level, marker, message, params);
981        }
982    }
983
984    @Override
985    public void logIfEnabled(final String fqcn, final Level level, final Marker marker, final String message,
986            final Throwable t) {
987        if (isEnabled(level, marker, message, t)) {
988            logMessage(fqcn, level, marker, message, t);
989        }
990    }
991
992    protected void logMessage(final String fqcn, final Level level, final Marker marker, final Object message,
993            final Throwable t) {
994        logMessage(fqcn, level, marker, messageFactory.newMessage(message), t);
995    }
996
997    protected void logMessage(final String fqcn, final Level level, final Marker marker,
998            final MessageSupplier msgSupplier, final Throwable t) {
999        final Message message = LambdaUtil.get(msgSupplier);
1000        logMessage(fqcn, level, marker, message, t);
1001    }
1002
1003    protected void logMessage(final String fqcn, final Level level, final Marker marker, final Supplier<?> msgSupplier,
1004            final Throwable t) {
1005        final Object message = LambdaUtil.get(msgSupplier);
1006        logMessage(fqcn, level, marker, messageFactory.newMessage(message), t);
1007    }
1008
1009    protected void logMessage(final String fqcn, final Level level, final Marker marker, final String message,
1010            final Throwable t) {
1011        logMessage(fqcn, level, marker, messageFactory.newMessage(message), t);
1012    }
1013
1014    protected void logMessage(final String fqcn, final Level level, final Marker marker, final String message) {
1015        final Message msg = messageFactory.newMessage(message);
1016        logMessage(fqcn, level, marker, msg, msg.getThrowable());
1017    }
1018
1019    protected void logMessage(final String fqcn, final Level level, final Marker marker, final String message,
1020            final Object... params) {
1021        final Message msg = messageFactory.newMessage(message, params);
1022        logMessage(fqcn, level, marker, msg, msg.getThrowable());
1023    }
1024
1025    protected void logMessage(final String fqcn, final Level level, final Marker marker, final String message,
1026            final Supplier<?>... paramSuppliers) {
1027        final Message msg = messageFactory.newMessage(message, LambdaUtil.getAll(paramSuppliers));
1028        logMessage(fqcn, level, marker, msg, msg.getThrowable());
1029    }
1030
1031    @Override
1032    public void printf(final Level level, final Marker marker, final String format, final Object... params) {
1033        if (isEnabled(level, marker, format, params)) {
1034            final Message msg = new StringFormattedMessage(format, params);
1035            logMessage(FQCN, level, marker, msg, msg.getThrowable());
1036        }
1037    }
1038
1039    @Override
1040    public void printf(final Level level, final String format, final Object... params) {
1041        if (isEnabled(level, null, format, params)) {
1042            final Message msg = new StringFormattedMessage(format, params);
1043            logMessage(FQCN, level, null, msg, msg.getThrowable());
1044        }
1045    }
1046
1047    @Override
1048    public <T extends Throwable> T throwing(final T t) {
1049        return throwing(FQCN, Level.ERROR, t);
1050    }
1051
1052    @Override
1053    public <T extends Throwable> T throwing(final Level level, final T t) {
1054        return throwing(FQCN, level, t);
1055    }
1056
1057    /**
1058     * Logs a Throwable to be thrown.
1059     *
1060     * @param <T> the type of the Throwable.
1061     * @param fqcn the fully qualified class name of this Logger implementation.
1062     * @param level The logging Level.
1063     * @param t The Throwable.
1064     * @return the Throwable.
1065     */
1066    protected <T extends Throwable> T throwing(final String fqcn, final Level level, final T t) {
1067        if (isEnabled(level, THROWING_MARKER, (Object) null, null)) {
1068            logMessage(fqcn, level, THROWING_MARKER, throwingMsg(t), t);
1069        }
1070        return t;
1071    }
1072
1073    protected Message throwingMsg(final Throwable t) {
1074        return messageFactory.newMessage(THROWING);
1075    }
1076
1077    @Override
1078    public void trace(final Marker marker, final Message msg) {
1079        logIfEnabled(FQCN, Level.TRACE, marker, msg, null);
1080    }
1081
1082    @Override
1083    public void trace(final Marker marker, final Message msg, final Throwable t) {
1084        logIfEnabled(FQCN, Level.TRACE, marker, msg, t);
1085    }
1086
1087    @Override
1088    public void trace(final Marker marker, final Object message) {
1089        logIfEnabled(FQCN, Level.TRACE, marker, message, null);
1090    }
1091
1092    @Override
1093    public void trace(final Marker marker, final Object message, final Throwable t) {
1094        logIfEnabled(FQCN, Level.TRACE, marker, message, t);
1095    }
1096
1097    @Override
1098    public void trace(final Marker marker, final String message) {
1099        logIfEnabled(FQCN, Level.TRACE, marker, message, (Throwable) null);
1100    }
1101
1102    @Override
1103    public void trace(final Marker marker, final String message, final Object... params) {
1104        logIfEnabled(FQCN, Level.TRACE, marker, message, params);
1105    }
1106
1107    @Override
1108    public void trace(final Marker marker, final String message, final Throwable t) {
1109        logIfEnabled(FQCN, Level.TRACE, marker, message, t);
1110    }
1111
1112    @Override
1113    public void trace(final Message msg) {
1114        logIfEnabled(FQCN, Level.TRACE, null, msg, null);
1115    }
1116
1117    @Override
1118    public void trace(final Message msg, final Throwable t) {
1119        logIfEnabled(FQCN, Level.TRACE, null, msg, t);
1120    }
1121
1122    @Override
1123    public void trace(final Object message) {
1124        logIfEnabled(FQCN, Level.TRACE, null, message, null);
1125    }
1126
1127    @Override
1128    public void trace(final Object message, final Throwable t) {
1129        logIfEnabled(FQCN, Level.TRACE, null, message, t);
1130    }
1131
1132    @Override
1133    public void trace(final String message) {
1134        logIfEnabled(FQCN, Level.TRACE, null, message, (Throwable) null);
1135    }
1136
1137    @Override
1138    public void trace(final String message, final Object... params) {
1139        logIfEnabled(FQCN, Level.TRACE, null, message, params);
1140    }
1141
1142    @Override
1143    public void trace(final String message, final Throwable t) {
1144        logIfEnabled(FQCN, Level.TRACE, null, message, t);
1145    }
1146
1147    @Override
1148    public void trace(final Supplier<?> msgSupplier) {
1149        logIfEnabled(FQCN, Level.TRACE, null, msgSupplier, (Throwable) null);
1150    }
1151
1152    @Override
1153    public void trace(final Supplier<?> msgSupplier, final Throwable t) {
1154        logIfEnabled(FQCN, Level.TRACE, null, msgSupplier, t);
1155    }
1156
1157    @Override
1158    public void trace(final Marker marker, final Supplier<?> msgSupplier) {
1159        logIfEnabled(FQCN, Level.TRACE, marker, msgSupplier, (Throwable) null);
1160    }
1161
1162    @Override
1163    public void trace(final Marker marker, final String message, final Supplier<?>... paramSuppliers) {
1164        logIfEnabled(FQCN, Level.TRACE, marker, message, paramSuppliers);
1165    }
1166
1167    @Override
1168    public void trace(final Marker marker, final Supplier<?> msgSupplier, final Throwable t) {
1169        logIfEnabled(FQCN, Level.TRACE, marker, msgSupplier, t);
1170    }
1171
1172    @Override
1173    public void trace(final String message, final Supplier<?>... paramSuppliers) {
1174        logIfEnabled(FQCN, Level.TRACE, null, message, paramSuppliers);
1175    }
1176
1177    @Override
1178    public void trace(final Marker marker, final MessageSupplier msgSupplier) {
1179        logIfEnabled(FQCN, Level.TRACE, marker, msgSupplier, (Throwable) null);
1180    }
1181
1182    @Override
1183    public void trace(final Marker marker, final MessageSupplier msgSupplier, final Throwable t) {
1184        logIfEnabled(FQCN, Level.TRACE, marker, msgSupplier, t);
1185    }
1186
1187    @Override
1188    public void trace(final MessageSupplier msgSupplier) {
1189        logIfEnabled(FQCN, Level.TRACE, null, msgSupplier, (Throwable) null);
1190    }
1191
1192    @Override
1193    public void trace(final MessageSupplier msgSupplier, final Throwable t) {
1194        logIfEnabled(FQCN, Level.TRACE, null, msgSupplier, t);
1195    }
1196
1197    @Override
1198    public void warn(final Marker marker, final Message msg) {
1199        logIfEnabled(FQCN, Level.WARN, marker, msg, null);
1200    }
1201
1202    @Override
1203    public void warn(final Marker marker, final Message msg, final Throwable t) {
1204        logIfEnabled(FQCN, Level.WARN, marker, msg, t);
1205    }
1206
1207    @Override
1208    public void warn(final Marker marker, final Object message) {
1209        logIfEnabled(FQCN, Level.WARN, marker, message, null);
1210    }
1211
1212    @Override
1213    public void warn(final Marker marker, final Object message, final Throwable t) {
1214        logIfEnabled(FQCN, Level.WARN, marker, message, t);
1215    }
1216
1217    @Override
1218    public void warn(final Marker marker, final String message) {
1219        logIfEnabled(FQCN, Level.WARN, marker, message, (Throwable) null);
1220    }
1221
1222    @Override
1223    public void warn(final Marker marker, final String message, final Object... params) {
1224        logIfEnabled(FQCN, Level.WARN, marker, message, params);
1225    }
1226
1227    @Override
1228    public void warn(final Marker marker, final String message, final Throwable t) {
1229        logIfEnabled(FQCN, Level.WARN, marker, message, t);
1230    }
1231
1232    @Override
1233    public void warn(final Message msg) {
1234        logIfEnabled(FQCN, Level.WARN, null, msg, null);
1235    }
1236
1237    @Override
1238    public void warn(final Message msg, final Throwable t) {
1239        logIfEnabled(FQCN, Level.WARN, null, msg, t);
1240    }
1241
1242    @Override
1243    public void warn(final Object message) {
1244        logIfEnabled(FQCN, Level.WARN, null, message, null);
1245    }
1246
1247    @Override
1248    public void warn(final Object message, final Throwable t) {
1249        logIfEnabled(FQCN, Level.WARN, null, message, t);
1250    }
1251
1252    @Override
1253    public void warn(final String message) {
1254        logIfEnabled(FQCN, Level.WARN, null, message, (Throwable) null);
1255    }
1256
1257    @Override
1258    public void warn(final String message, final Object... params) {
1259        logIfEnabled(FQCN, Level.WARN, null, message, params);
1260    }
1261
1262    @Override
1263    public void warn(final String message, final Throwable t) {
1264        logIfEnabled(FQCN, Level.WARN, null, message, t);
1265    }
1266
1267    @Override
1268    public void warn(final Supplier<?> msgSupplier) {
1269        logIfEnabled(FQCN, Level.WARN, null, msgSupplier, (Throwable) null);
1270    }
1271
1272    @Override
1273    public void warn(final Supplier<?> msgSupplier, final Throwable t) {
1274        logIfEnabled(FQCN, Level.WARN, null, msgSupplier, t);
1275    }
1276
1277    @Override
1278    public void warn(final Marker marker, final Supplier<?> msgSupplier) {
1279        logIfEnabled(FQCN, Level.WARN, marker, msgSupplier, (Throwable) null);
1280    }
1281
1282    @Override
1283    public void warn(final Marker marker, final String message, final Supplier<?>... paramSuppliers) {
1284        logIfEnabled(FQCN, Level.WARN, marker, message, paramSuppliers);
1285    }
1286
1287    @Override
1288    public void warn(final Marker marker, final Supplier<?> msgSupplier, final Throwable t) {
1289        logIfEnabled(FQCN, Level.WARN, marker, msgSupplier, t);
1290    }
1291
1292    @Override
1293    public void warn(final String message, final Supplier<?>... paramSuppliers) {
1294        logIfEnabled(FQCN, Level.WARN, null, message, paramSuppliers);
1295    }
1296
1297    @Override
1298    public void warn(final Marker marker, final MessageSupplier msgSupplier) {
1299        logIfEnabled(FQCN, Level.WARN, marker, msgSupplier, (Throwable) null);
1300    }
1301
1302    @Override
1303    public void warn(final Marker marker, final MessageSupplier msgSupplier, final Throwable t) {
1304        logIfEnabled(FQCN, Level.WARN, marker, msgSupplier, t);
1305    }
1306
1307    @Override
1308    public void warn(final MessageSupplier msgSupplier) {
1309        logIfEnabled(FQCN, Level.WARN, null, msgSupplier, (Throwable) null);
1310    }
1311
1312    @Override
1313    public void warn(final MessageSupplier msgSupplier, final Throwable t) {
1314        logIfEnabled(FQCN, Level.WARN, null, msgSupplier, t);
1315    }
1316}