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 org.apache.logging.log4j.Level;
020import org.apache.logging.log4j.Logger;
021import org.apache.logging.log4j.Marker;
022import org.apache.logging.log4j.MarkerManager;
023import org.apache.logging.log4j.message.Message;
024import org.apache.logging.log4j.message.MessageFactory;
025import org.apache.logging.log4j.message.ParameterizedMessageFactory;
026import org.apache.logging.log4j.message.StringFormattedMessage;
027import org.apache.logging.log4j.status.StatusLogger;
028
029import java.io.Serializable;
030
031/**
032 * Base implementation of a Logger. It is highly recommended that any Logger implementation extend this class.
033 */
034public abstract class AbstractLogger implements Logger, Serializable {
035
036    private static final long serialVersionUID = 2L;
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", FLOW_MARKER);
047
048    /**
049     * Marker for method exit tracing.
050     */
051    public static final Marker EXIT_MARKER = MarkerManager.getMarker("EXIT", 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", EXCEPTION_MARKER);
062
063    /**
064     * Marker for catching exceptions.
065     */
066    public static final Marker CATCHING_MARKER = MarkerManager.getMarker("CATCHING", EXCEPTION_MARKER);
067
068    /**
069     * The default MessageFactory class.
070     */
071    public static final Class<? extends MessageFactory> DEFAULT_MESSAGE_FACTORY_CLASS = ParameterizedMessageFactory.class;
072
073    private static final String FQCN = AbstractLogger.class.getName();
074
075    private static final String THROWING = "throwing";
076
077    private static final String CATCHING = "catching";
078
079    /**
080     * Checks that the message factory a logger was created with is the same as the given messageFactory. If they are
081     * different log a warning to the {@linkplain StatusLogger}. A null MessageFactory translates to the default
082     * MessageFactory {@link #DEFAULT_MESSAGE_FACTORY_CLASS}.
083     * 
084     * @param logger The logger to check
085     * @param messageFactory The message factory to check.
086     */
087    public static void checkMessageFactory(final Logger logger, final MessageFactory messageFactory) {
088        final String name = logger.getName();
089        final MessageFactory loggerMessageFactory = logger.getMessageFactory();
090        if (messageFactory != null && !loggerMessageFactory.equals(messageFactory)) {
091            StatusLogger.getLogger().warn(
092                    "The Logger {} was created with the message factory {} and is now requested with the "
093                            + "message factory {}, which may create log events with unexpected formatting.", name,
094                    loggerMessageFactory, messageFactory);
095        } else if (messageFactory == null && !loggerMessageFactory.getClass().equals(DEFAULT_MESSAGE_FACTORY_CLASS)) {
096            StatusLogger
097                    .getLogger()
098                    .warn("The Logger {} was created with the message factory {} and is now requested with a null "
099                            + "message factory (defaults to {}), which may create log events with unexpected formatting.",
100                            name, loggerMessageFactory, DEFAULT_MESSAGE_FACTORY_CLASS.getName());
101        }
102    }
103
104    private final String name;
105
106    private final MessageFactory messageFactory;
107
108    /**
109     * Creates a new logger named after the class (or subclass).
110     */
111    public AbstractLogger() {
112        this.name = getClass().getName();
113        this.messageFactory = createDefaultMessageFactory();
114    }
115
116    /**
117     * Creates a new named logger.
118     * 
119     * @param name the logger name
120     */
121    public AbstractLogger(final String name) {
122        this.name = name;
123        this.messageFactory = createDefaultMessageFactory();
124    }
125
126    /**
127     * Creates a new named logger.
128     * 
129     * @param name the logger name
130     * @param messageFactory the message factory, if null then use the default message factory.
131     */
132    public AbstractLogger(final String name, final MessageFactory messageFactory) {
133        this.name = name;
134        this.messageFactory = messageFactory == null ? createDefaultMessageFactory() : messageFactory;
135    }
136
137    /**
138     * Logs a Throwable that has been caught.
139     * 
140     * @param level The logging Level.
141     * @param t The Throwable.
142     */
143    @Override
144    public void catching(final Level level, final Throwable t) {
145        catching(FQCN, level, t);
146    }
147
148    /**
149     * Logs a Throwable that has been caught with location information.
150     * 
151     * @param fqcn The fully qualified class name of the <b>caller</b>.
152     * @param level The logging level.
153     * @param t The Throwable.
154     */
155    protected void catching(final String fqcn, final Level level, final Throwable t) {
156        if (isEnabled(level, CATCHING_MARKER, (Object) null, null)) {
157            log(CATCHING_MARKER, fqcn, level, messageFactory.newMessage(CATCHING), t);
158        }
159    }
160
161    /**
162     * Logs a Throwable at the {@link Level#ERROR ERROR} level..
163     * 
164     * @param t The Throwable.
165     */
166    @Override
167    public void catching(final Throwable t) {
168        catching(FQCN, Level.ERROR, t);
169    }
170
171    private MessageFactory createDefaultMessageFactory() {
172        try {
173            return DEFAULT_MESSAGE_FACTORY_CLASS.newInstance();
174        } catch (final InstantiationException e) {
175            throw new IllegalStateException(e);
176        } catch (final IllegalAccessException e) {
177            throw new IllegalStateException(e);
178        }
179    }
180
181    /**
182     * Logs a message with the specific Marker at the DEBUG level.
183     * 
184     * @param marker the marker data specific to this log statement
185     * @param msg the message string to be logged
186     */
187    @Override
188    public void debug(final Marker marker, final Message msg) {
189        if (isEnabled(Level.DEBUG, marker, msg, null)) {
190            log(marker, FQCN, Level.DEBUG, msg, null);
191        }
192    }
193
194    /**
195     * Logs a message with the specific Marker at the DEBUG level.
196     * 
197     * @param marker the marker data specific to this log statement.
198     * @param msg the message string to be logged
199     * @param t A Throwable or null.
200     */
201    @Override
202    public void debug(final Marker marker, final Message msg, final Throwable t) {
203        if (isEnabled(Level.DEBUG, marker, msg, t)) {
204            log(marker, FQCN, Level.DEBUG, msg, t);
205        }
206    }
207
208    /**
209     * Logs a message object with the {@link Level#DEBUG DEBUG} level.
210     * 
211     * @param marker the marker data specific to this log statement.
212     * @param message the message object to log.
213     */
214    @Override
215    public void debug(final Marker marker, final Object message) {
216        if (isEnabled(Level.DEBUG, marker, message, null)) {
217            log(marker, FQCN, Level.DEBUG, messageFactory.newMessage(message), null);
218        }
219    }
220
221    /**
222     * Logs a message at the {@link Level#DEBUG DEBUG} level including the stack trace of the {@link Throwable}
223     * <code>t</code> passed as parameter.
224     * 
225     * @param marker the marker data specific to this log statement.
226     * @param message the message to log.
227     * @param t the exception to log, including its stack trace.
228     */
229    @Override
230    public void debug(final Marker marker, final Object message, final Throwable t) {
231        if (isEnabled(Level.DEBUG, marker, message, t)) {
232            log(marker, FQCN, Level.DEBUG, messageFactory.newMessage(message), t);
233        }
234    }
235
236    /**
237     * Logs a message object with the {@link Level#DEBUG DEBUG} level.
238     * 
239     * @param marker the marker data specific to this log statement.
240     * @param message the message object to log.
241     */
242    @Override
243    public void debug(final Marker marker, final String message) {
244        if (isEnabled(Level.DEBUG, marker, message)) {
245            log(marker, FQCN, Level.DEBUG, messageFactory.newMessage(message), null);
246        }
247    }
248
249    /**
250     * Logs a message with parameters at the {@link Level#DEBUG DEBUG} level.
251     * 
252     * @param marker the marker data specific to this log statement.
253     * @param message the message to log.
254     * @param params parameters to the message.
255     */
256    @Override
257    public void debug(final Marker marker, final String message, final Object... params) {
258        if (isEnabled(Level.DEBUG, marker, message, params)) {
259            final Message msg = messageFactory.newMessage(message, params);
260            log(marker, FQCN, Level.DEBUG, msg, msg.getThrowable());
261        }
262    }
263
264    /**
265     * Logs a message at the {@link Level#DEBUG DEBUG} level including the stack trace of the {@link Throwable}
266     * <code>t</code> passed as parameter.
267     * 
268     * @param marker the marker data specific to this log statement.
269     * @param message the message to log.
270     * @param t the exception to log, including its stack trace.
271     */
272    @Override
273    public void debug(final Marker marker, final String message, final Throwable t) {
274        if (isEnabled(Level.DEBUG, marker, message, t)) {
275            log(marker, FQCN, Level.DEBUG, messageFactory.newMessage(message), t);
276        }
277    }
278
279    /**
280     * Logs a message with the specific Marker at the DEBUG level.
281     * 
282     * @param msg the message string to be logged
283     */
284    @Override
285    public void debug(final Message msg) {
286        if (isEnabled(Level.DEBUG, null, msg, null)) {
287            log(null, FQCN, Level.DEBUG, msg, null);
288        }
289    }
290
291    /**
292     * Logs a message with the specific Marker at the DEBUG level.
293     * 
294     * @param msg the message string to be logged
295     * @param t A Throwable or null.
296     */
297    @Override
298    public void debug(final Message msg, final Throwable t) {
299        if (isEnabled(Level.DEBUG, null, msg, t)) {
300            log(null, FQCN, Level.DEBUG, msg, t);
301        }
302    }
303
304    /**
305     * Logs a message object with the {@link Level#DEBUG DEBUG} level.
306     * 
307     * @param message the message object to log.
308     */
309    @Override
310    public void debug(final Object message) {
311        if (isEnabled(Level.DEBUG, null, message, null)) {
312            log(null, FQCN, Level.DEBUG, messageFactory.newMessage(message), null);
313        }
314    }
315
316    /**
317     * Logs a message at the {@link Level#DEBUG DEBUG} level including the stack trace of the {@link Throwable}
318     * <code>t</code> passed as parameter.
319     * 
320     * @param message the message to log.
321     * @param t the exception to log, including its stack trace.
322     */
323    @Override
324    public void debug(final Object message, final Throwable t) {
325        if (isEnabled(Level.DEBUG, null, message, t)) {
326            log(null, FQCN, Level.DEBUG, messageFactory.newMessage(message), t);
327        }
328    }
329
330    /**
331     * Logs a message object with the {@link Level#DEBUG DEBUG} level.
332     * 
333     * @param message the message object to log.
334     */
335    @Override
336    public void debug(final String message) {
337        if (isEnabled(Level.DEBUG, null, message)) {
338            log(null, FQCN, Level.DEBUG, messageFactory.newMessage(message), null);
339        }
340    }
341
342    /**
343     * Logs a message with parameters at the {@link Level#DEBUG DEBUG} level.
344     * 
345     * @param message the message to log.
346     * @param params parameters to the message.
347     */
348    @Override
349    public void debug(final String message, final Object... params) {
350        if (isEnabled(Level.DEBUG, null, message, params)) {
351            final Message msg = messageFactory.newMessage(message, params);
352            log(null, FQCN, Level.DEBUG, msg, msg.getThrowable());
353        }
354    }
355
356    /**
357     * Logs a message at the {@link Level#DEBUG DEBUG} level including the stack trace of the {@link Throwable}
358     * <code>t</code> passed as parameter.
359     * 
360     * @param message the message to log.
361     * @param t the exception to log, including its stack trace.
362     */
363    @Override
364    public void debug(final String message, final Throwable t) {
365        if (isEnabled(Level.DEBUG, null, message, t)) {
366            log(null, FQCN, Level.DEBUG, messageFactory.newMessage(message), t);
367        }
368    }
369
370    /**
371     * Logs entry to a method.
372     */
373    @Override
374    public void entry() {
375        entry(FQCN);
376    }
377
378    /**
379     * Logs entry to a method.
380     * 
381     * @param params The parameters to the method.
382     */
383    @Override
384    public void entry(final Object... params) {
385        entry(FQCN, params);
386    }
387
388    /**
389     * Logs entry to a method with location information.
390     * 
391     * @param fqcn The fully qualified class name of the <b>caller</b>.
392     * @param params The parameters to the method.
393     */
394    protected void entry(final String fqcn, final Object... params) {
395        if (isEnabled(Level.TRACE, ENTRY_MARKER, (Object) null, null)) {
396            log(ENTRY_MARKER, fqcn, Level.TRACE, entryMsg(params.length, params), null);
397        }
398    }
399
400    private Message entryMsg(final int count, final Object... params) {
401        if (count == 0) {
402            return messageFactory.newMessage("entry");
403        }
404        final StringBuilder sb = new StringBuilder("entry params(");
405        int i = 0;
406        for (final Object parm : params) {
407            if (parm != null) {
408                sb.append(parm.toString());
409            } else {
410                sb.append("null");
411            }
412            if (++i < params.length) {
413                sb.append(", ");
414            }
415        }
416        sb.append(")");
417        return messageFactory.newMessage(sb.toString());
418    }
419
420    /**
421     * Logs a message with the specific Marker at the {@link Level#ERROR ERROR} level.
422     * 
423     * @param marker the marker data specific to this log statement
424     * @param msg the message string to be logged
425     */
426    @Override
427    public void error(final Marker marker, final Message msg) {
428        if (isEnabled(Level.ERROR, marker, msg, null)) {
429            log(marker, FQCN, Level.ERROR, msg, null);
430        }
431    }
432
433    /**
434     * Logs a message with the specific Marker at the {@link Level#ERROR ERROR} level.
435     * 
436     * @param marker the marker data specific to this log statement
437     * @param msg the message string to be logged
438     * @param t A Throwable or null.
439     */
440    @Override
441    public void error(final Marker marker, final Message msg, final Throwable t) {
442        if (isEnabled(Level.ERROR, marker, msg, t)) {
443            log(marker, FQCN, Level.ERROR, msg, t);
444        }
445    }
446
447    /**
448     * Logs a message object with the {@link Level#ERROR ERROR} level.
449     * 
450     * @param marker the marker data specific to this log statement.
451     * @param message the message object to log.
452     */
453    @Override
454    public void error(final Marker marker, final Object message) {
455        if (isEnabled(Level.ERROR, marker, message, null)) {
456            log(marker, FQCN, Level.ERROR, messageFactory.newMessage(message), null);
457        }
458    }
459
460    /**
461     * Logs a message at the {@link Level#ERROR ERROR} level including the stack trace of the {@link Throwable}
462     * <code>t</code> passed as parameter.
463     * 
464     * @param marker the marker data specific to this log statement.
465     * @param message the message object to log.
466     * @param t the exception to log, including its stack trace.
467     */
468    @Override
469    public void error(final Marker marker, final Object message, final Throwable t) {
470        if (isEnabled(Level.ERROR, marker, message, t)) {
471            log(marker, FQCN, Level.ERROR, messageFactory.newMessage(message), t);
472        }
473    }
474
475    /**
476     * Logs a message object with the {@link Level#ERROR ERROR} level.
477     * 
478     * @param marker the marker data specific to this log statement.
479     * @param message the message object to log.
480     */
481    @Override
482    public void error(final Marker marker, final String message) {
483        if (isEnabled(Level.ERROR, marker, message)) {
484            log(marker, FQCN, Level.ERROR, messageFactory.newMessage(message), null);
485        }
486    }
487
488    /**
489     * Logs a message with parameters at the {@link Level#ERROR ERROR} level.
490     * 
491     * @param marker the marker data specific to this log statement.
492     * @param message the message to log.
493     * @param params parameters to the message.
494     */
495    @Override
496    public void error(final Marker marker, final String message, final Object... params) {
497        if (isEnabled(Level.ERROR, marker, message, params)) {
498            final Message msg = messageFactory.newMessage(message, params);
499            log(marker, FQCN, Level.ERROR, msg, msg.getThrowable());
500        }
501    }
502
503    /**
504     * Logs a message at the {@link Level#ERROR ERROR} level including the stack trace of the {@link Throwable}
505     * <code>t</code> passed as parameter.
506     * 
507     * @param marker the marker data specific to this log statement.
508     * @param message the message object to log.
509     * @param t the exception to log, including its stack trace.
510     */
511    @Override
512    public void error(final Marker marker, final String message, final Throwable t) {
513        if (isEnabled(Level.ERROR, marker, message, t)) {
514            log(marker, FQCN, Level.ERROR, messageFactory.newMessage(message), t);
515        }
516    }
517
518    /**
519     * Logs a message with the specific Marker at the {@link Level#ERROR ERROR} level.
520     * 
521     * @param msg the message string to be logged
522     */
523    @Override
524    public void error(final Message msg) {
525        if (isEnabled(Level.ERROR, null, msg, null)) {
526            log(null, FQCN, Level.ERROR, msg, null);
527        }
528    }
529
530    /**
531     * Logs a message with the specific Marker at the {@link Level#ERROR ERROR} level.
532     * 
533     * @param msg the message string to be logged
534     * @param t A Throwable or null.
535     */
536    @Override
537    public void error(final Message msg, final Throwable t) {
538        if (isEnabled(Level.ERROR, null, msg, t)) {
539            log(null, FQCN, Level.ERROR, msg, t);
540        }
541    }
542
543    /**
544     * Logs a message object with the {@link Level#ERROR ERROR} level.
545     * 
546     * @param message the message object to log.
547     */
548    @Override
549    public void error(final Object message) {
550        if (isEnabled(Level.ERROR, null, message, null)) {
551            log(null, FQCN, Level.ERROR, messageFactory.newMessage(message), null);
552        }
553    }
554
555    /**
556     * Logs a message at the {@link Level#ERROR ERROR} level including the stack trace of the {@link Throwable}
557     * <code>t</code> passed as parameter.
558     * 
559     * @param message the message object to log.
560     * @param t the exception to log, including its stack trace.
561     */
562    @Override
563    public void error(final Object message, final Throwable t) {
564        if (isEnabled(Level.ERROR, null, message, t)) {
565            log(null, FQCN, Level.ERROR, messageFactory.newMessage(message), t);
566        }
567    }
568
569    /**
570     * Logs a message object with the {@link Level#ERROR ERROR} level.
571     * 
572     * @param message the message object to log.
573     */
574    @Override
575    public void error(final String message) {
576        if (isEnabled(Level.ERROR, null, message)) {
577            log(null, FQCN, Level.ERROR, messageFactory.newMessage(message), null);
578        }
579    }
580
581    /**
582     * Logs a message with parameters at the {@link Level#ERROR ERROR} level.
583     * 
584     * @param message the message to log.
585     * @param params parameters to the message.
586     */
587    @Override
588    public void error(final String message, final Object... params) {
589        if (isEnabled(Level.ERROR, null, message, params)) {
590            final Message msg = messageFactory.newMessage(message, params);
591            log(null, FQCN, Level.ERROR, msg, msg.getThrowable());
592        }
593    }
594
595    /**
596     * Logs a message at the {@link Level#ERROR ERROR} level including the stack trace of the {@link Throwable}
597     * <code>t</code> passed as parameter.
598     * 
599     * @param message the message object to log.
600     * @param t the exception to log, including its stack trace.
601     */
602    @Override
603    public void error(final String message, final Throwable t) {
604        if (isEnabled(Level.ERROR, null, message, t)) {
605            log(null, FQCN, Level.ERROR, messageFactory.newMessage(message), t);
606        }
607    }
608
609    /**
610     * Logs exit from a method.
611     */
612    @Override
613    public void exit() {
614        exit(FQCN, null);
615    }
616
617    /**
618     * Logs exiting from a method with the result.
619     * 
620     * @param <R> The type of the parameter and object being returned.
621     * @param result The result being returned from the method call.
622     * @return the Throwable.
623     */
624    @Override
625    public <R> R exit(final R result) {
626        return exit(FQCN, result);
627    }
628
629    /**
630     * Logs exiting from a method with the result and location information.
631     * 
632     * @param fqcn The fully qualified class name of the <b>caller</b>.
633     * @param <R> The type of the parameter and object being returned.
634     * @param result The result being returned from the method call.
635     */
636    protected <R> R exit(final String fqcn, final R result) {
637        if (isEnabled(Level.TRACE, EXIT_MARKER, (Object) null, null)) {
638            log(EXIT_MARKER, fqcn, Level.TRACE, toExitMsg(result), null);
639        }
640        return result;
641    }
642
643    /**
644     * Logs a message with the specific Marker at the FATAL level.
645     * 
646     * @param marker the marker data specific to this log statement
647     * @param msg the message string to be logged
648     */
649    @Override
650    public void fatal(final Marker marker, final Message msg) {
651        if (isEnabled(Level.FATAL, marker, msg, null)) {
652            log(marker, FQCN, Level.FATAL, msg, null);
653        }
654    }
655
656    /**
657     * Logs a message with the specific Marker at the FATAL level.
658     * 
659     * @param marker the marker data specific to this log statement
660     * @param msg the message string to be logged
661     * @param t A Throwable or null.
662     */
663    @Override
664    public void fatal(final Marker marker, final Message msg, final Throwable t) {
665        if (isEnabled(Level.FATAL, marker, msg, t)) {
666            log(marker, FQCN, Level.FATAL, msg, t);
667        }
668    }
669
670    /**
671     * Logs a message object with the {@link Level#FATAL FATAL} level.
672     * 
673     * @param marker the marker data specific to this log statement.
674     * @param message the message object to log.
675     */
676    @Override
677    public void fatal(final Marker marker, final Object message) {
678        if (isEnabled(Level.FATAL, marker, message, null)) {
679            log(marker, FQCN, Level.FATAL, messageFactory.newMessage(message), null);
680        }
681    }
682
683    /**
684     * Logs a message at the {@link Level#FATAL FATAL} level including the stack trace of the {@link Throwable}
685     * <code>t</code> passed as parameter.
686     * 
687     * @param marker the marker data specific to this log statement.
688     * @param message the message object to log.
689     * @param t the exception to log, including its stack trace.
690     */
691    @Override
692    public void fatal(final Marker marker, final Object message, final Throwable t) {
693        if (isEnabled(Level.FATAL, marker, message, t)) {
694            log(marker, FQCN, Level.FATAL, messageFactory.newMessage(message), t);
695        }
696    }
697
698    /**
699     * Logs a message object with the {@link Level#FATAL FATAL} level.
700     * 
701     * @param marker the marker data specific to this log statement.
702     * @param message the message object to log.
703     */
704    @Override
705    public void fatal(final Marker marker, final String message) {
706        if (isEnabled(Level.FATAL, marker, message)) {
707            log(marker, FQCN, Level.FATAL, messageFactory.newMessage(message), null);
708        }
709    }
710
711    /**
712     * Logs a message with parameters at the {@link Level#FATAL FATAL} level.
713     * 
714     * @param marker the marker data specific to this log statement.
715     * @param message the message to log.
716     * @param params parameters to the message.
717     */
718    @Override
719    public void fatal(final Marker marker, final String message, final Object... params) {
720        if (isEnabled(Level.FATAL, marker, message, params)) {
721            final Message msg = messageFactory.newMessage(message, params);
722            log(marker, FQCN, Level.FATAL, msg, msg.getThrowable());
723        }
724    }
725
726    /**
727     * Logs a message at the {@link Level#FATAL FATAL} level including the stack trace of the {@link Throwable}
728     * <code>t</code> passed as parameter.
729     * 
730     * @param marker the marker data specific to this log statement.
731     * @param message the message object to log.
732     * @param t the exception to log, including its stack trace.
733     */
734    @Override
735    public void fatal(final Marker marker, final String message, final Throwable t) {
736        if (isEnabled(Level.FATAL, marker, message, t)) {
737            log(marker, FQCN, Level.FATAL, messageFactory.newMessage(message), t);
738        }
739    }
740
741    /**
742     * Logs a message with the specific Marker at the FATAL level.
743     * 
744     * @param msg the message string to be logged
745     */
746    @Override
747    public void fatal(final Message msg) {
748        if (isEnabled(Level.FATAL, null, msg, null)) {
749            log(null, FQCN, Level.FATAL, msg, null);
750        }
751    }
752
753    /**
754     * Logs a message with the specific Marker at the FATAL level.
755     * 
756     * @param msg the message string to be logged
757     * @param t A Throwable or null.
758     */
759    @Override
760    public void fatal(final Message msg, final Throwable t) {
761        if (isEnabled(Level.FATAL, null, msg, t)) {
762            log(null, FQCN, Level.FATAL, msg, t);
763        }
764    }
765
766    /**
767     * Logs a message object with the {@link Level#FATAL FATAL} level.
768     * 
769     * @param message the message object to log.
770     */
771    @Override
772    public void fatal(final Object message) {
773        if (isEnabled(Level.FATAL, null, message, null)) {
774            log(null, FQCN, Level.FATAL, messageFactory.newMessage(message), null);
775        }
776    }
777
778    /**
779     * Logs a message at the {@link Level#FATAL FATAL} level including the stack trace of the {@link Throwable}
780     * <code>t</code> passed as parameter.
781     * 
782     * @param message the message object to log.
783     * @param t the exception to log, including its stack trace.
784     */
785    @Override
786    public void fatal(final Object message, final Throwable t) {
787        if (isEnabled(Level.FATAL, null, message, t)) {
788            log(null, FQCN, Level.FATAL, messageFactory.newMessage(message), t);
789        }
790    }
791
792    /**
793     * Logs a message object with the {@link Level#FATAL FATAL} level.
794     * 
795     * @param message the message object to log.
796     */
797    @Override
798    public void fatal(final String message) {
799        if (isEnabled(Level.FATAL, null, message)) {
800            log(null, FQCN, Level.FATAL, messageFactory.newMessage(message), null);
801        }
802    }
803
804    /**
805     * Logs a message with parameters at the {@link Level#FATAL FATAL} level.
806     * 
807     * @param message the message to log.
808     * @param params parameters to the message.
809     */
810    @Override
811    public void fatal(final String message, final Object... params) {
812        if (isEnabled(Level.FATAL, null, message, params)) {
813            final Message msg = messageFactory.newMessage(message, params);
814            log(null, FQCN, Level.FATAL, msg, msg.getThrowable());
815        }
816    }
817
818    /**
819     * Logs a message at the {@link Level#FATAL FATAL} level including the stack trace of the {@link Throwable}
820     * <code>t</code> passed as parameter.
821     * 
822     * @param message the message object to log.
823     * @param t the exception to log, including its stack trace.
824     */
825    @Override
826    public void fatal(final String message, final Throwable t) {
827        if (isEnabled(Level.FATAL, null, message, t)) {
828            log(null, FQCN, Level.FATAL, messageFactory.newMessage(message), t);
829        }
830    }
831
832    /**
833     * Gets the message factory.
834     * 
835     * @return the message factory.
836     */
837    @Override
838    public MessageFactory getMessageFactory() {
839        return messageFactory;
840    }
841
842    /*
843     * (non-Javadoc)
844     * 
845     * @see org.apache.logging.log4j.Logger#getName()
846     */
847    @Override
848    public String getName() {
849        return name;
850    }
851
852    /**
853     * Gets a print stream that logs lines to this logger.
854     * 
855     * @param level the logging level
856     * @return print stream that logs printed lines to this logger.
857     */
858    @Override
859    public LoggerStream getStream(final Level level) {
860        return new LoggerStream(this, level);
861    }
862
863    /**
864     * Gets a marked print stream that logs lines to this logger.
865     * 
866     * @param marker the marker data specific to this log statement
867     * @param level the logging level
868     * @return print stream that logs printed lines to this logger.
869     */
870    @Override
871    public LoggerStream getStream(Marker marker, Level level) {
872        return new LoggerStream(this, marker, level);
873    }
874
875    /**
876     * Logs a message with the specific Marker at the INFO level.
877     * 
878     * @param marker the marker data specific to this log statement
879     * @param msg the message string to be logged
880     */
881    @Override
882    public void info(final Marker marker, final Message msg) {
883        if (isEnabled(Level.INFO, marker, msg, null)) {
884            log(marker, FQCN, Level.INFO, msg, null);
885        }
886    }
887
888    /**
889     * Logs a message with the specific Marker at the INFO level.
890     * 
891     * @param marker the marker data specific to this log statement
892     * @param msg the message string to be logged
893     * @param t A Throwable or null.
894     */
895    @Override
896    public void info(final Marker marker, final Message msg, final Throwable t) {
897        if (isEnabled(Level.INFO, marker, msg, t)) {
898            log(marker, FQCN, Level.INFO, msg, t);
899        }
900    }
901
902    /**
903     * Logs a message object with the {@link Level#INFO INFO} level.
904     * 
905     * @param marker the marker data specific to this log statement.
906     * @param message the message object to log.
907     */
908    @Override
909    public void info(final Marker marker, final Object message) {
910        if (isEnabled(Level.INFO, marker, message, null)) {
911            log(marker, FQCN, Level.INFO, messageFactory.newMessage(message), null);
912        }
913    }
914
915    /**
916     * Logs a message at the {@link Level#INFO INFO} level including the stack trace of the {@link Throwable}
917     * <code>t</code> passed as parameter.
918     * 
919     * @param marker the marker data specific to this log statement.
920     * @param message the message object to log.
921     * @param t the exception to log, including its stack trace.
922     */
923    @Override
924    public void info(final Marker marker, final Object message, final Throwable t) {
925        if (isEnabled(Level.INFO, marker, message, t)) {
926            log(marker, FQCN, Level.INFO, messageFactory.newMessage(message), t);
927        }
928    }
929
930    /**
931     * Logs a message object with the {@link Level#INFO INFO} level.
932     * 
933     * @param marker the marker data specific to this log statement.
934     * @param message the message object to log.
935     */
936    @Override
937    public void info(final Marker marker, final String message) {
938        if (isEnabled(Level.INFO, marker, message)) {
939            log(marker, FQCN, Level.INFO, messageFactory.newMessage(message), null);
940        }
941    }
942
943    /**
944     * Logs a message with parameters at the {@link Level#INFO INFO} level.
945     * 
946     * @param marker the marker data specific to this log statement.
947     * @param message the message to log.
948     * @param params parameters to the message.
949     */
950    @Override
951    public void info(final Marker marker, final String message, final Object... params) {
952        if (isEnabled(Level.INFO, marker, message, params)) {
953            final Message msg = messageFactory.newMessage(message, params);
954            log(marker, FQCN, Level.INFO, msg, msg.getThrowable());
955        }
956    }
957
958    /**
959     * Logs a message at the {@link Level#INFO INFO} level including the stack trace of the {@link Throwable}
960     * <code>t</code> passed as parameter.
961     * 
962     * @param marker the marker data specific to this log statement.
963     * @param message the message object to log.
964     * @param t the exception to log, including its stack trace.
965     */
966    @Override
967    public void info(final Marker marker, final String message, final Throwable t) {
968        if (isEnabled(Level.INFO, marker, message, t)) {
969            log(marker, FQCN, Level.INFO, messageFactory.newMessage(message), t);
970        }
971    }
972
973    /**
974     * Logs a message with the specific Marker at the TRACE level.
975     * 
976     * @param msg the message string to be logged
977     */
978    @Override
979    public void info(final Message msg) {
980        if (isEnabled(Level.INFO, null, msg, null)) {
981            log(null, FQCN, Level.INFO, msg, null);
982        }
983    }
984
985    /**
986     * Logs a message with the specific Marker at the INFO level.
987     * 
988     * @param msg the message string to be logged
989     * @param t A Throwable or null.
990     */
991    @Override
992    public void info(final Message msg, final Throwable t) {
993        if (isEnabled(Level.INFO, null, msg, t)) {
994            log(null, FQCN, Level.INFO, msg, t);
995        }
996    }
997
998    /**
999     * Logs a message object with the {@link Level#INFO INFO} level.
1000     * 
1001     * @param message the message object to log.
1002     */
1003    @Override
1004    public void info(final Object message) {
1005        if (isEnabled(Level.INFO, null, message, null)) {
1006            log(null, FQCN, Level.INFO, messageFactory.newMessage(message), null);
1007        }
1008    }
1009
1010    /**
1011     * Logs a message at the {@link Level#INFO INFO} level including the stack trace of the {@link Throwable}
1012     * <code>t</code> passed as parameter.
1013     * 
1014     * @param message the message object to log.
1015     * @param t the exception to log, including its stack trace.
1016     */
1017    @Override
1018    public void info(final Object message, final Throwable t) {
1019        if (isEnabled(Level.INFO, null, message, t)) {
1020            log(null, FQCN, Level.INFO, messageFactory.newMessage(message), t);
1021        }
1022    }
1023
1024    /**
1025     * Logs a message object with the {@link Level#INFO INFO} level.
1026     * 
1027     * @param message the message object to log.
1028     */
1029    @Override
1030    public void info(final String message) {
1031        if (isEnabled(Level.INFO, null, message)) {
1032            log(null, FQCN, Level.INFO, messageFactory.newMessage(message), null);
1033        }
1034    }
1035
1036    /**
1037     * Logs a message with parameters at the {@link Level#INFO INFO} level.
1038     * 
1039     * @param message the message to log.
1040     * @param params parameters to the message.
1041     */
1042    @Override
1043    public void info(final String message, final Object... params) {
1044        if (isEnabled(Level.INFO, null, message, params)) {
1045            final Message msg = messageFactory.newMessage(message, params);
1046            log(null, FQCN, Level.INFO, msg, msg.getThrowable());
1047        }
1048    }
1049
1050    /**
1051     * Logs a message at the {@link Level#INFO INFO} level including the stack trace of the {@link Throwable}
1052     * <code>t</code> passed as parameter.
1053     * 
1054     * @param message the message object to log.
1055     * @param t the exception to log, including its stack trace.
1056     */
1057    @Override
1058    public void info(final String message, final Throwable t) {
1059        if (isEnabled(Level.INFO, null, message, t)) {
1060            log(null, FQCN, Level.INFO, messageFactory.newMessage(message), t);
1061        }
1062    }
1063
1064    /**
1065     * Checks whether this Logger is enabled for the DEBUG Level.
1066     * 
1067     * @return boolean - {@code true} if this Logger is enabled for level DEBUG, {@code false} otherwise.
1068     */
1069    @Override
1070    public boolean isDebugEnabled() {
1071        return isEnabled(Level.DEBUG, null, null);
1072    }
1073
1074    /**
1075     * Checks whether this Logger is enabled for the DEBUG Level.
1076     * 
1077     * @param marker The marker data.
1078     * @return boolean - {@code true} if this Logger is enabled for level DEBUG, {@code false} otherwise.
1079     */
1080    @Override
1081    public boolean isDebugEnabled(final Marker marker) {
1082        return isEnabled(Level.DEBUG, marker, (Object) null, null);
1083    }
1084
1085    /**
1086     * Checks whether this Logger is enabled for the the given Level.
1087     * <p>
1088     * Note that passing in {@link Level#OFF OFF} always returns {@code true}.
1089     * </p>
1090     * 
1091     * @param level the level to check
1092     * @return boolean - {@code true} if this Logger is enabled for level, {@code false} otherwise.
1093     */
1094    @Override
1095    public boolean isEnabled(final Level level) {
1096        return isEnabled(level, null, (Object) null, null);
1097    }
1098
1099    @Override
1100    public boolean isEnabled(final Level level, final Marker marker) {
1101        return isEnabled(level, marker, (Object) null, null);
1102    }
1103
1104    /**
1105     * Determine if logging is enabled.
1106     * 
1107     * @param level The logging Level to check.
1108     * @param marker A Marker or null.
1109     * @param data The Message.
1110     * @param t A Throwable.
1111     * @return True if logging is enabled, false otherwise.
1112     */
1113    protected abstract boolean isEnabled(Level level, Marker marker, Message data, Throwable t);
1114
1115    /**
1116     * Determine if logging is enabled.
1117     * 
1118     * @param level The logging Level to check.
1119     * @param marker A Marker or null.
1120     * @param data The message.
1121     * @param t A Throwable.
1122     * @return True if logging is enabled, false otherwise.
1123     */
1124    protected abstract boolean isEnabled(Level level, Marker marker, Object data, Throwable t);
1125
1126    /**
1127     * Determine if logging is enabled.
1128     * 
1129     * @param level The logging Level to check.
1130     * @param marker A Marker or null.
1131     * @param data The message.
1132     * @return True if logging is enabled, false otherwise.
1133     */
1134    protected abstract boolean isEnabled(Level level, Marker marker, String data);
1135
1136    /**
1137     * Determine if logging is enabled.
1138     * 
1139     * @param level The logging Level to check.
1140     * @param marker A Marker or null.
1141     * @param data The message.
1142     * @param p1 The parameters.
1143     * @return True if logging is enabled, false otherwise.
1144     */
1145    protected abstract boolean isEnabled(Level level, Marker marker, String data, Object... p1);
1146
1147    /**
1148     * Determine if logging is enabled.
1149     * 
1150     * @param level The logging Level to check.
1151     * @param marker A Marker or null.
1152     * @param data The message.
1153     * @param t A Throwable.
1154     * @return True if logging is enabled, false otherwise.
1155     */
1156    protected abstract boolean isEnabled(Level level, Marker marker, String data, Throwable t);
1157
1158    /**
1159     * Checks whether this Logger is enabled for the {@link Level#ERROR ERROR} Level.
1160     * 
1161     * @return boolean - {@code true} if this Logger is enabled for level {@link Level#ERROR ERROR}, {@code false}
1162     *         otherwise.
1163     */
1164    @Override
1165    public boolean isErrorEnabled() {
1166        return isEnabled(Level.ERROR, null, (Object) null, null);
1167    }
1168
1169    /**
1170     * Checks whether this Logger is enabled for the {@link Level#ERROR ERROR} Level.
1171     * 
1172     * @param marker The marker data.
1173     * @return boolean - {@code true} if this Logger is enabled for level {@link Level#ERROR ERROR}, {@code false}
1174     *         otherwise.
1175     */
1176    @Override
1177    public boolean isErrorEnabled(final Marker marker) {
1178        return isEnabled(Level.ERROR, marker, (Object) null, null);
1179    }
1180
1181    /**
1182     * Checks whether this Logger is enabled for the FATAL Level.
1183     * 
1184     * @return boolean - {@code true} if this Logger is enabled for level FATAL, {@code false} otherwise.
1185     */
1186    @Override
1187    public boolean isFatalEnabled() {
1188        return isEnabled(Level.FATAL, null, (Object) null, null);
1189    }
1190
1191    /**
1192     * Checks whether this Logger is enabled for the FATAL Level.
1193     * 
1194     * @param marker The marker data.
1195     * @return boolean - {@code true} if this Logger is enabled for level FATAL, {@code false} otherwise.
1196     */
1197    @Override
1198    public boolean isFatalEnabled(final Marker marker) {
1199        return isEnabled(Level.FATAL, marker, (Object) null, null);
1200    }
1201
1202    /**
1203     * Checks whether this Logger is enabled for the INFO Level.
1204     * 
1205     * @return boolean - {@code true} if this Logger is enabled for level INFO, {@code false} otherwise.
1206     */
1207    @Override
1208    public boolean isInfoEnabled() {
1209        return isEnabled(Level.INFO, null, (Object) null, null);
1210    }
1211
1212    /**
1213     * Checks whether this Logger is enabled for the INFO Level.
1214     * 
1215     * @param marker The marker data.
1216     * @return boolean - {@code true} if this Logger is enabled for level INFO, {@code false} otherwise.
1217     */
1218    @Override
1219    public boolean isInfoEnabled(final Marker marker) {
1220        return isEnabled(Level.INFO, marker, (Object) null, null);
1221    }
1222
1223    /**
1224     * Checks whether this Logger is enabled for the TRACE Level.
1225     * 
1226     * @return boolean - {@code true} if this Logger is enabled for level TRACE, {@code false} otherwise.
1227     */
1228    @Override
1229    public boolean isTraceEnabled() {
1230        return isEnabled(Level.TRACE, null, (Object) null, null);
1231    }
1232
1233    /**
1234     * Checks whether this Logger is enabled for the TRACE Level.
1235     * 
1236     * @param marker The marker data.
1237     * @return boolean - {@code true} if this Logger is enabled for level TRACE, {@code false} otherwise.
1238     */
1239    @Override
1240    public boolean isTraceEnabled(final Marker marker) {
1241        return isEnabled(Level.TRACE, marker, (Object) null, null);
1242    }
1243
1244    /**
1245     * Checks whether this Logger is enabled for the WARN Level.
1246     * 
1247     * @return boolean - {@code true} if this Logger is enabled for level WARN, {@code false} otherwise.
1248     */
1249    @Override
1250    public boolean isWarnEnabled() {
1251        return isEnabled(Level.WARN, null, (Object) null, null);
1252    }
1253
1254    /**
1255     * Checks whether this Logger is enabled for the WARN Level.
1256     * 
1257     * @param marker The marker data.
1258     * @return boolean - {@code true} if this Logger is enabled for level WARN, {@code false} otherwise.
1259     */
1260    @Override
1261    public boolean isWarnEnabled(final Marker marker) {
1262        return isEnabled(Level.WARN, marker, (Object) null, null);
1263    }
1264
1265    /**
1266     * Logs a message with the specific Marker at the given level.
1267     * 
1268     * @param level the logging level
1269     * @param marker the marker data specific to this log statement
1270     * @param msg the message string to be logged
1271     */
1272    @Override
1273    public void log(final Level level, final Marker marker, final Message msg) {
1274        if (isEnabled(level, marker, msg, null)) {
1275            log(marker, FQCN, level, msg, null);
1276        }
1277    }
1278
1279    /**
1280     * Logs a message with the specific Marker at the given level.
1281     * 
1282     * @param level the logging level
1283     * @param marker the marker data specific to this log statement.
1284     * @param msg the message string to be logged
1285     * @param t A Throwable or null.
1286     */
1287    @Override
1288    public void log(final Level level, final Marker marker, final Message msg, final Throwable t) {
1289        if (isEnabled(level, marker, msg, t)) {
1290            log(marker, FQCN, level, msg, t);
1291        }
1292    }
1293
1294    /**
1295     * Logs a message object with the given level.
1296     * 
1297     * @param level the logging level
1298     * @param marker the marker data specific to this log statement.
1299     * @param message the message object to log.
1300     */
1301    @Override
1302    public void log(final Level level, final Marker marker, final Object message) {
1303        if (isEnabled(level, marker, message, null)) {
1304            log(marker, FQCN, level, messageFactory.newMessage(message), null);
1305        }
1306    }
1307
1308    /**
1309     * Logs a message at the given level including the stack trace of the {@link Throwable} <code>t</code> passed as
1310     * parameter.
1311     * 
1312     * @param level the logging level
1313     * @param marker the marker data specific to this log statement.
1314     * @param message the message to log.
1315     * @param t the exception to log, including its stack trace.
1316     */
1317    @Override
1318    public void log(final Level level, final Marker marker, final Object message, final Throwable t) {
1319        if (isEnabled(level, marker, message, t)) {
1320            log(marker, FQCN, level, messageFactory.newMessage(message), t);
1321        }
1322    }
1323
1324    /**
1325     * Logs a message object with the given level.
1326     * 
1327     * @param level the logging level
1328     * @param marker the marker data specific to this log statement.
1329     * @param message the message object to log.
1330     */
1331    @Override
1332    public void log(final Level level, final Marker marker, final String message) {
1333        if (isEnabled(level, marker, message)) {
1334            log(marker, FQCN, level, messageFactory.newMessage(message), null);
1335        }
1336    }
1337
1338    /**
1339     * Logs a message with parameters at the given level.
1340     * 
1341     * @param level the logging level
1342     * @param marker the marker data specific to this log statement.
1343     * @param message the message to log.
1344     * @param params parameters to the message.
1345     */
1346    @Override
1347    public void log(final Level level, final Marker marker, final String message, final Object... params) {
1348        if (isEnabled(level, marker, message, params)) {
1349            final Message msg = messageFactory.newMessage(message, params);
1350            log(marker, FQCN, level, msg, msg.getThrowable());
1351        }
1352    }
1353
1354    /**
1355     * Logs a message at the given level including the stack trace of the {@link Throwable} <code>t</code> passed as
1356     * parameter.
1357     * 
1358     * @param level the logging level
1359     * @param marker the marker data specific to this log statement.
1360     * @param message the message to log.
1361     * @param t the exception to log, including its stack trace.
1362     */
1363    @Override
1364    public void log(final Level level, final Marker marker, final String message, final Throwable t) {
1365        if (isEnabled(level, marker, message, t)) {
1366            log(marker, FQCN, level, messageFactory.newMessage(message), t);
1367        }
1368    }
1369
1370    /**
1371     * Logs a message with the specific Marker at the given level.
1372     * 
1373     * @param level the logging level
1374     * @param msg the message string to be logged
1375     */
1376    @Override
1377    public void log(final Level level, final Message msg) {
1378        if (isEnabled(level, null, msg, null)) {
1379            log(null, FQCN, level, msg, null);
1380        }
1381    }
1382
1383    /**
1384     * Logs a message with the specific Marker at the given level.
1385     * 
1386     * @param level the logging level
1387     * @param msg the message string to be logged
1388     * @param t A Throwable or null.
1389     */
1390    @Override
1391    public void log(final Level level, final Message msg, final Throwable t) {
1392        if (isEnabled(level, null, msg, t)) {
1393            log(null, FQCN, level, msg, t);
1394        }
1395    }
1396
1397    /**
1398     * Logs a message object with the given level.
1399     * 
1400     * @param level the logging level
1401     * @param message the message object to log.
1402     */
1403    @Override
1404    public void log(final Level level, final Object message) {
1405        if (isEnabled(level, null, message, null)) {
1406            log(null, FQCN, level, messageFactory.newMessage(message), null);
1407        }
1408    }
1409
1410    /**
1411     * Logs a message at the given level including the stack trace of the {@link Throwable} <code>t</code> passed as
1412     * parameter.
1413     * 
1414     * @param level the logging level
1415     * @param message the message to log.
1416     * @param t the exception to log, including its stack trace.
1417     */
1418    @Override
1419    public void log(final Level level, final Object message, final Throwable t) {
1420        if (isEnabled(level, null, message, t)) {
1421            log(null, FQCN, level, messageFactory.newMessage(message), t);
1422        }
1423    }
1424
1425    /**
1426     * Logs a message object with the given level.
1427     * 
1428     * @param level the logging level
1429     * @param message the message object to log.
1430     */
1431    @Override
1432    public void log(final Level level, final String message) {
1433        if (isEnabled(level, null, message)) {
1434            log(null, FQCN, level, messageFactory.newMessage(message), null);
1435        }
1436    }
1437
1438    /**
1439     * Logs a message with parameters at the given level.
1440     * 
1441     * @param level the logging level
1442     * @param message the message to log.
1443     * @param params parameters to the message.
1444     */
1445    @Override
1446    public void log(final Level level, final String message, final Object... params) {
1447        if (isEnabled(level, null, message, params)) {
1448            final Message msg = messageFactory.newMessage(message, params);
1449            log(null, FQCN, level, msg, msg.getThrowable());
1450        }
1451    }
1452
1453    /**
1454     * Logs a message at the given level including the stack trace of the {@link Throwable} <code>t</code> passed as
1455     * parameter.
1456     * 
1457     * @param level the logging level
1458     * @param message the message to log.
1459     * @param t the exception to log, including its stack trace.
1460     */
1461    @Override
1462    public void log(final Level level, final String message, final Throwable t) {
1463        if (isEnabled(level, null, message, t)) {
1464            log(null, FQCN, level, messageFactory.newMessage(message), t);
1465        }
1466    }
1467
1468    /**
1469     * Logs a message with location information.
1470     * 
1471     * @param marker The Marker
1472     * @param fqcn The fully qualified class name of the <b>caller</b>
1473     * @param level The logging level
1474     * @param data The Message.
1475     * @param t A Throwable or null.
1476     */
1477    public abstract void log(Marker marker, String fqcn, Level level, Message data, Throwable t);
1478
1479    /**
1480     * Logs a formatted message using the specified format string and arguments.
1481     * 
1482     * @param level The logging Level.
1483     * @param marker the marker data specific to this log statement.
1484     * @param format The format String.
1485     * @param params Arguments specified by the format.
1486     */
1487    @Override
1488    public void printf(Level level, Marker marker, String format, Object... params) {
1489        if (isEnabled(level, marker, format, params)) {
1490            Message msg = new StringFormattedMessage(format, params);
1491            log(marker, FQCN, level, msg, msg.getThrowable());
1492        }
1493    }
1494
1495    /**
1496     * Logs a formatted message using the specified format string and arguments.
1497     * 
1498     * @param level The logging Level.
1499     * @param format The format String.
1500     * @param params Arguments specified by the format.
1501     */
1502    @Override
1503    public void printf(Level level, String format, Object... params) {
1504        if (isEnabled(level, null, format, params)) {
1505            Message msg = new StringFormattedMessage(format, params);
1506            log(null, FQCN, level, msg, msg.getThrowable());
1507        }
1508    }
1509
1510    /**
1511     * Logs a Throwable to be thrown.
1512     * 
1513     * @param <T> the type of the Throwable.
1514     * @param level The logging Level.
1515     * @param t The Throwable.
1516     * @return the Throwable.
1517     */
1518    @Override
1519    public <T extends Throwable> T throwing(final Level level, final T t) {
1520        return throwing(FQCN, level, t);
1521    }
1522
1523    /**
1524     * Logs a Throwable to be thrown with location information.
1525     * 
1526     * @param fqcn The fully qualified class name of the <b>caller</b>.
1527     * @param <T> the type of the Throwable.
1528     * @param level The logging Level.
1529     * @param t The Throwable.
1530     * @return the Throwable.
1531     */
1532    protected <T extends Throwable> T throwing(final String fqcn, final Level level, final T t) {
1533        if (isEnabled(level, THROWING_MARKER, (Object) null, null)) {
1534            log(THROWING_MARKER, fqcn, level, messageFactory.newMessage(THROWING), t);
1535        }
1536        return t;
1537    }
1538
1539    /**
1540     * Logs a Throwable to be thrown.
1541     * 
1542     * @param <T> the type of the Throwable.
1543     * @param t The Throwable.
1544     * @return the Throwable.
1545     */
1546    @Override
1547    public <T extends Throwable> T throwing(final T t) {
1548        return throwing(FQCN, Level.ERROR, t);
1549    }
1550
1551    private Message toExitMsg(final Object result) {
1552        if (result == null) {
1553            return messageFactory.newMessage("exit");
1554        }
1555        return messageFactory.newMessage("exit with(" + result + ")");
1556    }
1557
1558    /**
1559     * Returns a String representation of this instance in the form {@code "name"}.
1560     * 
1561     * @return A String describing this Logger instance.
1562     */
1563    @Override
1564    public String toString() {
1565        return name;
1566    }
1567
1568    /**
1569     * Logs a message with the specific Marker at the TRACE level.
1570     * 
1571     * @param marker the marker data specific to this log statement.
1572     * @param msg the message string to be logged
1573     */
1574    @Override
1575    public void trace(final Marker marker, final Message msg) {
1576        if (isEnabled(Level.TRACE, marker, msg, null)) {
1577            log(marker, FQCN, Level.TRACE, msg, null);
1578        }
1579    }
1580
1581    /**
1582     * Logs a message with the specific Marker at the TRACE level.
1583     * 
1584     * @param marker the marker data specific to this log statement.
1585     * @param msg the message string to be logged
1586     * @param t A Throwable or null.
1587     */
1588    @Override
1589    public void trace(final Marker marker, final Message msg, final Throwable t) {
1590        if (isEnabled(Level.TRACE, marker, msg, t)) {
1591            log(marker, FQCN, Level.TRACE, msg, t);
1592        }
1593    }
1594
1595    /**
1596     * Logs a message object with the {@link Level#TRACE TRACE} level.
1597     * 
1598     * @param marker the marker data specific to this log statement.
1599     * @param message the message object to log.
1600     */
1601    @Override
1602    public void trace(final Marker marker, final Object message) {
1603        if (isEnabled(Level.TRACE, marker, message, null)) {
1604            log(marker, FQCN, Level.TRACE, messageFactory.newMessage(message), null);
1605        }
1606    }
1607
1608    /**
1609     * Logs a message at the {@link Level#TRACE TRACE} level including the stack trace of the {@link Throwable}
1610     * <code>t</code> passed as parameter.
1611     * <p/>
1612     * <p>
1613     * See {@link #debug(String)} form for more detailed information.
1614     * </p>
1615     * 
1616     * @param marker the marker data specific to this log statement.
1617     * @param message the message object to log.
1618     * @param t the exception to log, including its stack trace.
1619     */
1620    @Override
1621    public void trace(final Marker marker, final Object message, final Throwable t) {
1622        if (isEnabled(Level.TRACE, marker, message, t)) {
1623            log(marker, FQCN, Level.TRACE, messageFactory.newMessage(message), t);
1624        }
1625    }
1626
1627    /**
1628     * Logs a message object with the {@link Level#TRACE TRACE} level.
1629     * 
1630     * @param marker the marker data specific to this log statement.
1631     * @param message the message object to log.
1632     */
1633    @Override
1634    public void trace(final Marker marker, final String message) {
1635        if (isEnabled(Level.TRACE, marker, message)) {
1636            log(marker, FQCN, Level.TRACE, messageFactory.newMessage(message), null);
1637        }
1638    }
1639
1640    /**
1641     * Logs a message with parameters at the {@link Level#TRACE TRACE} level.
1642     * 
1643     * @param marker the marker data specific to this log statement.
1644     * @param message the message to log.
1645     * @param params parameters to the message.
1646     */
1647    @Override
1648    public void trace(final Marker marker, final String message, final Object... params) {
1649        if (isEnabled(Level.TRACE, marker, message, params)) {
1650            final Message msg = messageFactory.newMessage(message, params);
1651            log(marker, FQCN, Level.TRACE, msg, msg.getThrowable());
1652        }
1653    }
1654
1655    /**
1656     * Logs a message at the {@link Level#TRACE TRACE} level including the stack trace of the {@link Throwable}
1657     * <code>t</code> passed as parameter.
1658     * <p/>
1659     * <p>
1660     * See {@link #debug(String)} form for more detailed information.
1661     * </p>
1662     * 
1663     * @param marker the marker data specific to this log statement.
1664     * @param message the message object to log.
1665     * @param t the exception to log, including its stack trace.
1666     */
1667    @Override
1668    public void trace(final Marker marker, final String message, final Throwable t) {
1669        if (isEnabled(Level.TRACE, marker, message, t)) {
1670            log(marker, FQCN, Level.TRACE, messageFactory.newMessage(message), t);
1671        }
1672    }
1673
1674    /**
1675     * Logs a message with the specific Marker at the TRACE level.
1676     * 
1677     * @param msg the message string to be logged
1678     */
1679    @Override
1680    public void trace(final Message msg) {
1681        if (isEnabled(Level.TRACE, null, msg, null)) {
1682            log(null, FQCN, Level.TRACE, msg, null);
1683        }
1684    }
1685
1686    /**
1687     * Logs a message with the specific Marker at the TRACE level.
1688     * 
1689     * @param msg the message string to be logged
1690     * @param t A Throwable or null.
1691     */
1692    @Override
1693    public void trace(final Message msg, final Throwable t) {
1694        if (isEnabled(Level.TRACE, null, msg, t)) {
1695            log(null, FQCN, Level.TRACE, msg, t);
1696        }
1697    }
1698
1699    /**
1700     * Logs a message object with the {@link Level#TRACE TRACE} level.
1701     * 
1702     * @param message the message object to log.
1703     */
1704    @Override
1705    public void trace(final Object message) {
1706        if (isEnabled(Level.TRACE, null, message, null)) {
1707            log(null, FQCN, Level.TRACE, messageFactory.newMessage(message), null);
1708        }
1709    }
1710
1711    /**
1712     * Logs a message at the {@link Level#TRACE TRACE} level including the stack trace of the {@link Throwable}
1713     * <code>t</code> passed as parameter.
1714     * <p/>
1715     * <p>
1716     * See {@link #debug(String)} form for more detailed information.
1717     * </p>
1718     * 
1719     * @param message the message object to log.
1720     * @param t the exception to log, including its stack trace.
1721     */
1722    @Override
1723    public void trace(final Object message, final Throwable t) {
1724        if (isEnabled(Level.TRACE, null, message, t)) {
1725            log(null, FQCN, Level.TRACE, messageFactory.newMessage(message), t);
1726        }
1727    }
1728
1729    /**
1730     * Logs a message object with the {@link Level#TRACE TRACE} level.
1731     * 
1732     * @param message the message object to log.
1733     */
1734    @Override
1735    public void trace(final String message) {
1736        if (isEnabled(Level.TRACE, null, message)) {
1737            log(null, FQCN, Level.TRACE, messageFactory.newMessage(message), null);
1738        }
1739    }
1740
1741    /**
1742     * Logs a message with parameters at the {@link Level#TRACE TRACE} level.
1743     * 
1744     * @param message the message to log.
1745     * @param params parameters to the message.
1746     */
1747    @Override
1748    public void trace(final String message, final Object... params) {
1749        if (isEnabled(Level.TRACE, null, message, params)) {
1750            final Message msg = messageFactory.newMessage(message, params);
1751            log(null, FQCN, Level.TRACE, msg, msg.getThrowable());
1752        }
1753    }
1754
1755    /**
1756     * Logs a message at the {@link Level#TRACE TRACE} level including the stack trace of the {@link Throwable}
1757     * <code>t</code> passed as parameter.
1758     * <p/>
1759     * <p>
1760     * See {@link #debug(String)} form for more detailed information.
1761     * </p>
1762     * 
1763     * @param message the message object to log.
1764     * @param t the exception to log, including its stack trace.
1765     */
1766    @Override
1767    public void trace(final String message, final Throwable t) {
1768        if (isEnabled(Level.TRACE, null, message, t)) {
1769            log(null, FQCN, Level.TRACE, messageFactory.newMessage(message), t);
1770        }
1771    }
1772
1773    /**
1774     * Logs a message with the specific Marker at the WARN level.
1775     * 
1776     * @param marker the marker data specific to this log statement
1777     * @param msg the message string to be logged
1778     */
1779    @Override
1780    public void warn(final Marker marker, final Message msg) {
1781        if (isEnabled(Level.WARN, marker, msg, null)) {
1782            log(marker, FQCN, Level.WARN, msg, null);
1783        }
1784    }
1785
1786    /**
1787     * Logs a message with the specific Marker at the WARN level.
1788     * 
1789     * @param marker the marker data specific to this log statement
1790     * @param msg the message string to be logged
1791     * @param t A Throwable or null.
1792     */
1793    @Override
1794    public void warn(final Marker marker, final Message msg, final Throwable t) {
1795        if (isEnabled(Level.WARN, marker, msg, t)) {
1796            log(marker, FQCN, Level.WARN, msg, t);
1797        }
1798    }
1799
1800    /**
1801     * Logs a message object with the {@link Level#WARN WARN} level.
1802     * 
1803     * @param marker the marker data specific to this log statement.
1804     * @param message the message object to log.
1805     */
1806    @Override
1807    public void warn(final Marker marker, final Object message) {
1808        if (isEnabled(Level.WARN, marker, message, null)) {
1809            log(marker, FQCN, Level.WARN, messageFactory.newMessage(message), null);
1810        }
1811    }
1812
1813    /*
1814     * Instead of one single method with Object... declared the following methods explicitly specify parameters because
1815     * they perform dramatically better than having the JVM convert them to an array.
1816     */
1817
1818    /**
1819     * Logs a message at the {@link Level#WARN WARN} level including the stack trace of the {@link Throwable}
1820     * <code>t</code> passed as parameter.
1821     * 
1822     * @param marker the marker data specific to this log statement.
1823     * @param message the message object to log.
1824     * @param t the exception to log, including its stack trace.
1825     */
1826    @Override
1827    public void warn(final Marker marker, final Object message, final Throwable t) {
1828        if (isEnabled(Level.WARN, marker, message, t)) {
1829            log(marker, FQCN, Level.WARN, messageFactory.newMessage(message), t);
1830        }
1831    }
1832
1833    /**
1834     * Logs a message object with the {@link Level#WARN WARN} level.
1835     * 
1836     * @param marker the marker data specific to this log statement.
1837     * @param message the message object to log.
1838     */
1839    @Override
1840    public void warn(final Marker marker, final String message) {
1841        if (isEnabled(Level.WARN, marker, message)) {
1842            log(marker, FQCN, Level.WARN, messageFactory.newMessage(message), null);
1843        }
1844    }
1845
1846    /**
1847     * Logs a message with parameters at the {@link Level#WARN WARN} level.
1848     * 
1849     * @param marker the marker data specific to this log statement.
1850     * @param message the message to log.
1851     * @param params parameters to the message.
1852     */
1853    @Override
1854    public void warn(final Marker marker, final String message, final Object... params) {
1855        if (isEnabled(Level.WARN, marker, message, params)) {
1856            final Message msg = messageFactory.newMessage(message, params);
1857            log(marker, FQCN, Level.WARN, msg, msg.getThrowable());
1858        }
1859    }
1860
1861    /**
1862     * Logs a message at the {@link Level#WARN WARN} level including the stack trace of the {@link Throwable}
1863     * <code>t</code> passed as parameter.
1864     * 
1865     * @param marker the marker data specific to this log statement.
1866     * @param message the message object to log.
1867     * @param t the exception to log, including its stack trace.
1868     */
1869    @Override
1870    public void warn(final Marker marker, final String message, final Throwable t) {
1871        if (isEnabled(Level.WARN, marker, message, t)) {
1872            log(marker, FQCN, Level.WARN, messageFactory.newMessage(message), t);
1873        }
1874    }
1875
1876    /**
1877     * Logs a message with the specific Marker at the WARN level.
1878     * 
1879     * @param msg the message string to be logged
1880     */
1881    @Override
1882    public void warn(final Message msg) {
1883        if (isEnabled(Level.WARN, null, msg, null)) {
1884            log(null, FQCN, Level.WARN, msg, null);
1885        }
1886    }
1887
1888    /**
1889     * Logs a message with the specific Marker at the WARN level.
1890     * 
1891     * @param msg the message string to be logged
1892     * @param t A Throwable or null.
1893     */
1894    @Override
1895    public void warn(final Message msg, final Throwable t) {
1896        if (isEnabled(Level.WARN, null, msg, t)) {
1897            log(null, FQCN, Level.WARN, msg, t);
1898        }
1899    }
1900
1901    /**
1902     * Logs a message object with the {@link Level#WARN WARN} level.
1903     * 
1904     * @param message the message object to log.
1905     */
1906    @Override
1907    public void warn(final Object message) {
1908        if (isEnabled(Level.WARN, null, message, null)) {
1909            log(null, FQCN, Level.WARN, messageFactory.newMessage(message), null);
1910        }
1911    }
1912
1913    /**
1914     * Logs a message at the {@link Level#WARN WARN} level including the stack trace of the {@link Throwable}
1915     * <code>t</code> passed as parameter.
1916     * 
1917     * @param message the message object to log.
1918     * @param t the exception to log, including its stack trace.
1919     */
1920    @Override
1921    public void warn(final Object message, final Throwable t) {
1922        if (isEnabled(Level.WARN, null, message, t)) {
1923            log(null, FQCN, Level.WARN, messageFactory.newMessage(message), t);
1924        }
1925    }
1926
1927    /**
1928     * Logs a message object with the {@link Level#WARN WARN} level.
1929     * 
1930     * @param message the message object to log.
1931     */
1932    @Override
1933    public void warn(final String message) {
1934        if (isEnabled(Level.WARN, null, message)) {
1935            log(null, FQCN, Level.WARN, messageFactory.newMessage(message), null);
1936        }
1937    }
1938
1939    /**
1940     * Logs a message with parameters at the {@link Level#WARN WARN} level.
1941     * 
1942     * @param message the message to log.
1943     * @param params parameters to the message.
1944     */
1945    @Override
1946    public void warn(final String message, final Object... params) {
1947        if (isEnabled(Level.WARN, null, message, params)) {
1948            final Message msg = messageFactory.newMessage(message, params);
1949            log(null, FQCN, Level.WARN, msg, msg.getThrowable());
1950        }
1951    }
1952
1953    /**
1954     * Logs a message at the {@link Level#WARN WARN} level including the stack trace of the {@link Throwable}
1955     * <code>t</code> passed as parameter.
1956     * 
1957     * @param message the message object to log.
1958     * @param t the exception to log, including its stack trace.
1959     */
1960    @Override
1961    public void warn(final String message, final Throwable t) {
1962        if (isEnabled(Level.WARN, null, message, t)) {
1963            log(null, FQCN, Level.WARN, messageFactory.newMessage(message), t);
1964        }
1965    }
1966
1967}