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     */
017    package org.apache.logging.log4j.spi;
018    
019    import java.io.Serializable;
020    
021    import org.apache.logging.log4j.Level;
022    import org.apache.logging.log4j.Marker;
023    import org.apache.logging.log4j.MarkerManager;
024    import org.apache.logging.log4j.message.Message;
025    import org.apache.logging.log4j.message.MessageFactory;
026    import org.apache.logging.log4j.message.ParameterizedMessageFactory;
027    import org.apache.logging.log4j.message.StringFormattedMessage;
028    import org.apache.logging.log4j.status.StatusLogger;
029    
030    /**
031     * Base implementation of a Logger. It is highly recommended that any Logger implementation extend this class.
032     */
033    public abstract class AbstractLogger implements ExtendedLogger, Serializable {
034    
035        private static final long serialVersionUID = 2L;
036    
037        /**
038         * Marker for flow tracing.
039         */
040        public static final Marker FLOW_MARKER = MarkerManager.getMarker("FLOW");
041    
042        /**
043         * Marker for method entry tracing.
044         */
045        public static final Marker ENTRY_MARKER = MarkerManager.getMarker("ENTRY").setParents(FLOW_MARKER);
046    
047        /**
048         * Marker for method exit tracing.
049         */
050        public static final Marker EXIT_MARKER = MarkerManager.getMarker("EXIT").setParents(FLOW_MARKER);
051    
052        /**
053         * Marker for exception tracing.
054         */
055        public static final Marker EXCEPTION_MARKER = MarkerManager.getMarker("EXCEPTION");
056    
057        /**
058         * Marker for throwing exceptions.
059         */
060        public static final Marker THROWING_MARKER = MarkerManager.getMarker("THROWING").setParents(EXCEPTION_MARKER);
061    
062        /**
063         * Marker for catching exceptions.
064         */
065        public static final Marker CATCHING_MARKER = MarkerManager.getMarker("CATCHING").setParents(EXCEPTION_MARKER);
066    
067        /**
068         * The default MessageFactory class.
069         */
070        public static final Class<? extends MessageFactory> DEFAULT_MESSAGE_FACTORY_CLASS = ParameterizedMessageFactory.class;
071    
072        private static final String FQCN = AbstractLogger.class.getName();
073    
074        private static final String THROWING = "throwing";
075    
076        private static final String CATCHING = "catching";
077    
078        /**
079         * Checks that the message factory a logger was created with is the same as the given messageFactory. If they are
080         * different log a warning to the {@linkplain StatusLogger}. A null MessageFactory translates to the default
081         * MessageFactory {@link #DEFAULT_MESSAGE_FACTORY_CLASS}.
082         *
083         * @param logger The logger to check
084         * @param messageFactory The message factory to check.
085         */
086        public static void checkMessageFactory(final ExtendedLogger logger, final MessageFactory messageFactory) {
087            final String name = logger.getName();
088            final MessageFactory loggerMessageFactory = logger.getMessageFactory();
089            if (messageFactory != null && !loggerMessageFactory.equals(messageFactory)) {
090                StatusLogger.getLogger().warn(
091                        "The Logger {} was created with the message factory {} and is now requested with the "
092                                + "message factory {}, which may create log events with unexpected formatting.", name,
093                        loggerMessageFactory, messageFactory);
094            } else if (messageFactory == null && !loggerMessageFactory.getClass().equals(DEFAULT_MESSAGE_FACTORY_CLASS)) {
095                StatusLogger
096                        .getLogger()
097                        .warn("The Logger {} was created with the message factory {} and is now requested with a null "
098                                + "message factory (defaults to {}), which may create log events with unexpected formatting.",
099                                name, loggerMessageFactory, DEFAULT_MESSAGE_FACTORY_CLASS.getName());
100            }
101        }
102    
103        private final String name;
104    
105        private final MessageFactory messageFactory;
106    
107        /**
108         * Creates a new logger named after this class (or subclass).
109         */
110        public AbstractLogger() {
111            this.name = getClass().getName();
112            this.messageFactory = createDefaultMessageFactory();
113        }
114    
115        /**
116         * Creates a new named logger.
117         *
118         * @param name the logger name
119         */
120        public AbstractLogger(final String name) {
121            this.name = name;
122            this.messageFactory = createDefaultMessageFactory();
123        }
124    
125        /**
126         * Creates a new named logger with a particular {@link MessageFactory}.
127         *
128         * @param name the logger name
129         * @param messageFactory the message factory, if null then use the default message factory.
130         */
131        public AbstractLogger(final String name, final MessageFactory messageFactory) {
132            this.name = name;
133            this.messageFactory = messageFactory == null ? createDefaultMessageFactory() : messageFactory;
134        }
135    
136        @Override
137        public void catching(final Level level, final Throwable t) {
138            catching(FQCN, level, t);
139        }
140    
141        /**
142         * Logs a Throwable that has been caught with location information.
143         *
144         * @param fqcn The fully qualified class name of the <b>caller</b>.
145         * @param level The logging level.
146         * @param t The Throwable.
147         */
148        protected void catching(final String fqcn, final Level level, final Throwable t) {
149            if (isEnabled(level, CATCHING_MARKER, (Object) null, null)) {
150                logMessage(fqcn, level, CATCHING_MARKER, catchingMsg(t), t);
151            }
152        }
153    
154        @Override
155        public void catching(final Throwable t) {
156            if (isEnabled(Level.ERROR, CATCHING_MARKER, (Object) null, null)) {
157                logMessage(FQCN, Level.ERROR, CATCHING_MARKER, catchingMsg(t), t);
158            }
159        }
160    
161        protected Message catchingMsg(final Throwable t) {
162            return messageFactory.newMessage(CATCHING);
163        }
164    
165        private MessageFactory createDefaultMessageFactory() {
166            try {
167                return DEFAULT_MESSAGE_FACTORY_CLASS.newInstance();
168            } catch (final InstantiationException e) {
169                throw new IllegalStateException(e);
170            } catch (final IllegalAccessException e) {
171                throw new IllegalStateException(e);
172            }
173        }
174    
175        @Override
176        public void debug(final Marker marker, final Message msg) {
177            logIfEnabled(FQCN, Level.DEBUG, marker, msg, null);
178        }
179    
180        @Override
181        public void debug(final Marker marker, final Message msg, final Throwable t) {
182            logIfEnabled(FQCN, Level.DEBUG, marker, msg, t);
183        }
184    
185        @Override
186        public void debug(final Marker marker, final Object message) {
187            logIfEnabled(FQCN, Level.DEBUG, marker, message, null);
188        }
189    
190        @Override
191        public void debug(final Marker marker, final Object message, final Throwable t) {
192            logIfEnabled(FQCN, Level.DEBUG, marker, message, t);
193        }
194    
195        @Override
196        public void debug(final Marker marker, final String message) {
197            logIfEnabled(FQCN, Level.DEBUG, marker, message, (Throwable) null);
198        }
199    
200        @Override
201        public void debug(final Marker marker, final String message, final Object... params) {
202            logIfEnabled(FQCN, Level.DEBUG, marker, message, params);
203        }
204    
205        @Override
206        public void debug(final Marker marker, final String message, final Throwable t) {
207            logIfEnabled(FQCN, Level.DEBUG, marker, message, t);
208        }
209    
210        @Override
211        public void debug(final Message msg) {
212            logIfEnabled(FQCN, Level.DEBUG, null, msg, null);
213        }
214    
215        @Override
216        public void debug(final Message msg, final Throwable t) {
217            logIfEnabled(FQCN, Level.DEBUG, null, msg, t);
218        }
219    
220        @Override
221        public void debug(final Object message) {
222            logIfEnabled(FQCN, Level.DEBUG, null, message, null);
223        }
224    
225        @Override
226        public void debug(final Object message, final Throwable t) {
227            logIfEnabled(FQCN, Level.DEBUG, null, message, t);
228        }
229    
230        @Override
231        public void debug(final String message) {
232            logIfEnabled(FQCN, Level.DEBUG, null, message, (Throwable) null);
233        }
234    
235        @Override
236        public void debug(final String message, final Object... params) {
237            logIfEnabled(FQCN, Level.DEBUG, null, message, params);
238        }
239    
240        @Override
241        public void debug(final String message, final Throwable t) {
242            logIfEnabled(FQCN, Level.DEBUG, null, message, t);
243        }
244    
245        @Override
246        public void entry() {
247            entry(FQCN);
248        }
249    
250        @Override
251        public void entry(final Object... params) {
252            entry(FQCN, params);
253        }
254    
255        /**
256         * Logs entry to a method with location information.
257         *
258         * @param fqcn The fully qualified class name of the <b>caller</b>.
259         * @param params The parameters to the method.
260         */
261        protected void entry(final String fqcn, final Object... params) {
262            if (isEnabled(Level.TRACE, ENTRY_MARKER, (Object) null, null)) {
263                logIfEnabled(fqcn, Level.TRACE, ENTRY_MARKER, entryMsg(params.length, params), null);
264            }
265        }
266    
267        protected Message entryMsg(final int count, final Object... params) {
268            if (count == 0) {
269                return messageFactory.newMessage("entry");
270            }
271            final StringBuilder sb = new StringBuilder("entry params(");
272            int i = 0;
273            for (final Object parm : params) {
274                if (parm != null) {
275                    sb.append(parm.toString());
276                } else {
277                    sb.append("null");
278                }
279                if (++i < params.length) {
280                    sb.append(", ");
281                }
282            }
283            sb.append(')');
284            return messageFactory.newMessage(sb.toString());
285        }
286    
287        @Override
288        public void error(final Marker marker, final Message msg) {
289            logIfEnabled(FQCN, Level.ERROR, marker, msg, null);
290        }
291    
292        @Override
293        public void error(final Marker marker, final Message msg, final Throwable t) {
294            logIfEnabled(FQCN, Level.ERROR, marker, msg, t);
295        }
296    
297        @Override
298        public void error(final Marker marker, final Object message) {
299            logIfEnabled(FQCN, Level.ERROR, marker, message, null);
300        }
301    
302        @Override
303        public void error(final Marker marker, final Object message, final Throwable t) {
304            logIfEnabled(FQCN, Level.ERROR, marker, message, t);
305        }
306    
307        @Override
308        public void error(final Marker marker, final String message) {
309            logIfEnabled(FQCN, Level.ERROR, marker, message, (Throwable) null);
310        }
311    
312        @Override
313        public void error(final Marker marker, final String message, final Object... params) {
314            logIfEnabled(FQCN, Level.ERROR, marker, message, params);
315        }
316    
317        @Override
318        public void error(final Marker marker, final String message, final Throwable t) {
319            logIfEnabled(FQCN, Level.ERROR, marker, message, t);
320        }
321    
322        @Override
323        public void error(final Message msg) {
324            logIfEnabled(FQCN, Level.ERROR, null, msg, null);
325        }
326    
327        @Override
328        public void error(final Message msg, final Throwable t) {
329            logIfEnabled(FQCN, Level.ERROR, null, msg, t);
330        }
331    
332        @Override
333        public void error(final Object message) {
334            logIfEnabled(FQCN, Level.ERROR, null, message, null);
335        }
336    
337        @Override
338        public void error(final Object message, final Throwable t) {
339            logIfEnabled(FQCN, Level.ERROR, null, message, t);
340        }
341    
342        @Override
343        public void error(final String message) {
344            logIfEnabled(FQCN, Level.ERROR, null, message, (Throwable) null);
345        }
346    
347        @Override
348        public void error(final String message, final Object... params) {
349            logIfEnabled(FQCN, Level.ERROR, null, message, params);
350        }
351    
352        @Override
353        public void error(final String message, final Throwable t) {
354            logIfEnabled(FQCN, Level.ERROR, null, message, t);
355        }
356    
357        @Override
358        public void exit() {
359            exit(FQCN, null);
360        }
361    
362        @Override
363        public <R> R exit(final R result) {
364            return exit(FQCN, result);
365        }
366    
367        /**
368         * Logs exiting from a method with the result and location information.
369         *
370         * @param fqcn The fully qualified class name of the <b>caller</b>.
371         * @param <R> The type of the parameter and object being returned.
372         * @param result The result being returned from the method call.
373         * @return the return value passed to this method.
374         */
375        protected <R> R exit(final String fqcn, final R result) {
376            if (isEnabled(Level.TRACE, EXIT_MARKER, (Object) null, null)) {
377                logIfEnabled(fqcn, Level.TRACE, EXIT_MARKER, exitMsg(result), null);
378            }
379            return result;
380        }
381    
382        protected Message exitMsg(final Object result) {
383            if (result == null) {
384                return messageFactory.newMessage("exit");
385            }
386            return messageFactory.newMessage("exit with(" + result + ')');
387        }
388    
389        @Override
390        public void fatal(final Marker marker, final Message msg) {
391            logIfEnabled(FQCN, Level.FATAL, marker, msg, null);
392        }
393    
394        @Override
395        public void fatal(final Marker marker, final Message msg, final Throwable t) {
396            logIfEnabled(FQCN, Level.FATAL, marker, msg, t);
397        }
398    
399        @Override
400        public void fatal(final Marker marker, final Object message) {
401            logIfEnabled(FQCN, Level.FATAL, marker, message, null);
402        }
403    
404        @Override
405        public void fatal(final Marker marker, final Object message, final Throwable t) {
406            logIfEnabled(FQCN, Level.FATAL, marker, message, t);
407        }
408    
409        @Override
410        public void fatal(final Marker marker, final String message) {
411            logIfEnabled(FQCN, Level.FATAL, marker, message, (Throwable) null);
412        }
413    
414        @Override
415        public void fatal(final Marker marker, final String message, final Object... params) {
416            logIfEnabled(FQCN, Level.FATAL, marker, message, params);
417        }
418    
419        @Override
420        public void fatal(final Marker marker, final String message, final Throwable t) {
421            logIfEnabled(FQCN, Level.FATAL, marker, message, t);
422        }
423    
424        @Override
425        public void fatal(final Message msg) {
426            logIfEnabled(FQCN, Level.FATAL, null, msg, null);
427        }
428    
429        @Override
430        public void fatal(final Message msg, final Throwable t) {
431            logIfEnabled(FQCN, Level.FATAL, null, msg, t);
432        }
433    
434        @Override
435        public void fatal(final Object message) {
436            logIfEnabled(FQCN, Level.FATAL, null, message, null);
437        }
438    
439        @Override
440        public void fatal(final Object message, final Throwable t) {
441            logIfEnabled(FQCN, Level.FATAL, null, message, t);
442        }
443    
444        @Override
445        public void fatal(final String message) {
446            logIfEnabled(FQCN, Level.FATAL, null, message, (Throwable) null);
447        }
448    
449        @Override
450        public void fatal(final String message, final Object... params) {
451            logIfEnabled(FQCN, Level.FATAL, null, message, params);
452        }
453    
454        @Override
455        public void fatal(final String message, final Throwable t) {
456            logIfEnabled(FQCN, Level.FATAL, null, message, t);
457        }
458    
459        @Override
460        public MessageFactory getMessageFactory() {
461            return messageFactory;
462        }
463    
464        @Override
465        public String getName() {
466            return name;
467        }
468    
469        @Override
470        public void info(final Marker marker, final Message msg) {
471            logIfEnabled(FQCN, Level.INFO, marker, msg, null);
472        }
473    
474        @Override
475        public void info(final Marker marker, final Message msg, final Throwable t) {
476            logIfEnabled(FQCN, Level.INFO, marker, msg, t);
477        }
478    
479        @Override
480        public void info(final Marker marker, final Object message) {
481            logIfEnabled(FQCN, Level.INFO, marker, message, null);
482        }
483    
484        @Override
485        public void info(final Marker marker, final Object message, final Throwable t) {
486            logIfEnabled(FQCN, Level.INFO, marker, message, t);
487        }
488    
489        @Override
490        public void info(final Marker marker, final String message) {
491            logIfEnabled(FQCN, Level.INFO, marker, message, (Throwable) null);
492        }
493    
494        @Override
495        public void info(final Marker marker, final String message, final Object... params) {
496            logIfEnabled(FQCN, Level.INFO, marker, message, params);
497        }
498    
499        @Override
500        public void info(final Marker marker, final String message, final Throwable t) {
501            logIfEnabled(FQCN, Level.INFO, marker, message, t);
502        }
503    
504        @Override
505        public void info(final Message msg) {
506            logIfEnabled(FQCN, Level.INFO, null, msg, null);
507        }
508    
509        @Override
510        public void info(final Message msg, final Throwable t) {
511            logIfEnabled(FQCN, Level.INFO, null, msg, t);
512        }
513    
514        @Override
515        public void info(final Object message) {
516            logIfEnabled(FQCN, Level.INFO, null, message, null);
517        }
518    
519        @Override
520        public void info(final Object message, final Throwable t) {
521            logIfEnabled(FQCN, Level.INFO, null, message, t);
522        }
523    
524        @Override
525        public void info(final String message) {
526            logIfEnabled(FQCN, Level.INFO, null, message, (Throwable) null);
527        }
528    
529        @Override
530        public void info(final String message, final Object... params) {
531            logIfEnabled(FQCN, Level.INFO, null, message, params);
532        }
533    
534        @Override
535        public void info(final String message, final Throwable t) {
536            logIfEnabled(FQCN, Level.INFO, null, message, t);
537        }
538    
539        @Override
540        public boolean isDebugEnabled() {
541            return isEnabled(Level.DEBUG, null, null);
542        }
543    
544        @Override
545        public boolean isDebugEnabled(final Marker marker) {
546            return isEnabled(Level.DEBUG, marker, (Object) null, null);
547        }
548    
549        @Override
550        public boolean isEnabled(final Level level) {
551            return isEnabled(level, null, (Object) null, null);
552        }
553    
554        @Override
555        public boolean isEnabled(final Level level, final Marker marker) {
556            return isEnabled(level, marker, (Object) null, null);
557        }
558    
559        @Override
560        public boolean isErrorEnabled() {
561            return isEnabled(Level.ERROR, null, (Object) null, null);
562        }
563    
564        @Override
565        public boolean isErrorEnabled(final Marker marker) {
566            return isEnabled(Level.ERROR, marker, (Object) null, null);
567        }
568    
569        @Override
570        public boolean isFatalEnabled() {
571            return isEnabled(Level.FATAL, null, (Object) null, null);
572        }
573    
574        @Override
575        public boolean isFatalEnabled(final Marker marker) {
576            return isEnabled(Level.FATAL, marker, (Object) null, null);
577        }
578    
579        @Override
580        public boolean isInfoEnabled() {
581            return isEnabled(Level.INFO, null, (Object) null, null);
582        }
583    
584        @Override
585        public boolean isInfoEnabled(final Marker marker) {
586            return isEnabled(Level.INFO, marker, (Object) null, null);
587        }
588    
589        @Override
590        public boolean isTraceEnabled() {
591            return isEnabled(Level.TRACE, null, (Object) null, null);
592        }
593    
594        @Override
595        public boolean isTraceEnabled(final Marker marker) {
596            return isEnabled(Level.TRACE, marker, (Object) null, null);
597        }
598    
599        @Override
600        public boolean isWarnEnabled() {
601            return isEnabled(Level.WARN, null, (Object) null, null);
602        }
603    
604        @Override
605        public boolean isWarnEnabled(final Marker marker) {
606            return isEnabled(Level.WARN, marker, (Object) null, null);
607        }
608    
609        @Override
610        public void log(final Level level, final Marker marker, final Message msg) {
611            logIfEnabled(FQCN, level, marker, msg, (Throwable) null);
612        }
613    
614        @Override
615        public void log(final Level level, final Marker marker, final Message msg, final Throwable t) {
616            logIfEnabled(FQCN, level, marker, msg, t);
617        }
618    
619        @Override
620        public void log(final Level level, final Marker marker, final Object message) {
621            logIfEnabled(FQCN, level, marker, message, (Throwable) null);
622        }
623    
624        @Override
625        public void log(final Level level, final Marker marker, final Object message, final Throwable t) {
626            if (isEnabled(level, marker, message, t)) {
627                logMessage(FQCN, level, marker, message, t);
628            }
629        }
630    
631        @Override
632        public void log(final Level level, final Marker marker, final String message) {
633            logIfEnabled(FQCN, level, marker, message, (Throwable) null);
634        }
635    
636        @Override
637        public void log(final Level level, final Marker marker, final String message, final Object... params) {
638            logIfEnabled(FQCN, level, marker, message, params);
639        }
640    
641        @Override
642        public void log(final Level level, final Marker marker, final String message, final Throwable t) {
643            logIfEnabled(FQCN, level, marker, message, t);
644        }
645    
646        @Override
647        public void log(final Level level, final Message msg) {
648            logIfEnabled(FQCN, level, null, msg, null);
649        }
650    
651        @Override
652        public void log(final Level level, final Message msg, final Throwable t) {
653            logIfEnabled(FQCN, level, null, msg, t);
654        }
655    
656        @Override
657        public void log(final Level level, final Object message) {
658            logIfEnabled(FQCN, level, null, message, null);
659        }
660    
661        @Override
662        public void log(final Level level, final Object message, final Throwable t) {
663            logIfEnabled(FQCN, level, null, message, t);
664        }
665    
666        @Override
667        public void log(final Level level, final String message) {
668            logIfEnabled(FQCN, level, null, message, (Throwable) null);
669        }
670    
671        @Override
672        public void log(final Level level, final String message, final Object... params) {
673            logIfEnabled(FQCN, level, null, message, params);
674        }
675    
676        @Override
677        public void log(final Level level, final String message, final Throwable t) {
678            logIfEnabled(FQCN, level, null, message, t);
679        }
680    
681        @Override
682        public void logIfEnabled(final String fqcn, final Level level, final Marker marker, final Message msg,
683                final Throwable t) {
684            if (isEnabled(level, marker, msg, t)) {
685                logMessage(fqcn, level, marker, msg, t);
686            }
687        }
688    
689        @Override
690        public void logIfEnabled(final String fqcn, final Level level, final Marker marker, final Object message,
691                final Throwable t) {
692            if (isEnabled(level, marker, message, t)) {
693                logMessage(fqcn, level, marker, message, t);
694            }
695        }
696    
697        @Override
698        public void logIfEnabled(final String fqcn, final Level level, final Marker marker, final String message) {
699            if (isEnabled(level, marker, message)) {
700                logMessage(fqcn, level, marker, message);
701            }
702        }
703    
704        @Override
705        public void logIfEnabled(final String fqcn, final Level level, final Marker marker, final String message,
706                final Object... params) {
707            if (isEnabled(level, marker, message, params)) {
708                logMessage(fqcn, level, marker, message, params);
709            }
710        }
711    
712        @Override
713        public void logIfEnabled(final String fqcn, final Level level, final Marker marker, final String message,
714                final Throwable t) {
715            if (isEnabled(level, marker, message, t)) {
716                logMessage(fqcn, level, marker, message, t);
717            }
718        }
719    
720        protected void logMessage(final String fqcn, final Level level, final Marker marker, final Object message,
721                final Throwable t) {
722            logMessage(fqcn, level, marker, messageFactory.newMessage(message), t);
723        }
724    
725        protected void logMessage(final String fqcn, final Level level, final Marker marker, final String message,
726                final Throwable t) {
727            logMessage(fqcn, level, marker, messageFactory.newMessage(message), t);
728        }
729    
730        protected void logMessage(final String fqcn, final Level level, final Marker marker, final String message) {
731            final Message msg = messageFactory.newMessage(message);
732            logMessage(fqcn, level, marker, msg, msg.getThrowable());
733        }
734    
735        protected void logMessage(final String fqcn, final Level level, final Marker marker, final String message,
736                final Object... params) {
737            final Message msg = messageFactory.newMessage(message, params);
738            logMessage(fqcn, level, marker, msg, msg.getThrowable());
739        }
740    
741        @Override
742        public void printf(final Level level, final Marker marker, final String format, final Object... params) {
743            if (isEnabled(level, marker, format, params)) {
744                final Message msg = new StringFormattedMessage(format, params);
745                logMessage(FQCN, level, marker, msg, msg.getThrowable());
746            }
747        }
748    
749        @Override
750        public void printf(final Level level, final String format, final Object... params) {
751            if (isEnabled(level, null, format, params)) {
752                final Message msg = new StringFormattedMessage(format, params);
753                logMessage(FQCN, level, null, msg, msg.getThrowable());
754            }
755        }
756    
757        @Override
758        public <T extends Throwable> T throwing(final T t) {
759            return throwing(FQCN, Level.ERROR, t);
760        }
761    
762        @Override
763        public <T extends Throwable> T throwing(final Level level, final T t) {
764            return throwing(FQCN, level, t);
765        }
766    
767        /**
768         * Logs a Throwable to be thrown.
769         *
770         * @param <T> the type of the Throwable.
771         * @param fqcn the fully qualified class name of this Logger implementation.
772         * @param level The logging Level.
773         * @param t The Throwable.
774         * @return the Throwable.
775         */
776        protected <T extends Throwable> T throwing(final String fqcn, final Level level, final T t) {
777            if (isEnabled(level, THROWING_MARKER, (Object) null, null)) {
778                logMessage(fqcn, level, THROWING_MARKER, throwingMsg(t), t);
779            }
780            return t;
781        }
782    
783        protected Message throwingMsg(final Throwable t) {
784            return messageFactory.newMessage(THROWING);
785        }
786    
787        @Override
788        public void trace(final Marker marker, final Message msg) {
789            logIfEnabled(FQCN, Level.TRACE, marker, msg, null);
790        }
791    
792        @Override
793        public void trace(final Marker marker, final Message msg, final Throwable t) {
794            logIfEnabled(FQCN, Level.TRACE, marker, msg, t);
795        }
796    
797        @Override
798        public void trace(final Marker marker, final Object message) {
799            logIfEnabled(FQCN, Level.TRACE, marker, message, null);
800        }
801    
802        @Override
803        public void trace(final Marker marker, final Object message, final Throwable t) {
804            logIfEnabled(FQCN, Level.TRACE, marker, message, t);
805        }
806    
807        @Override
808        public void trace(final Marker marker, final String message) {
809            logIfEnabled(FQCN, Level.TRACE, marker, message, (Throwable) null);
810        }
811    
812        @Override
813        public void trace(final Marker marker, final String message, final Object... params) {
814            logIfEnabled(FQCN, Level.TRACE, marker, message, params);
815        }
816    
817        @Override
818        public void trace(final Marker marker, final String message, final Throwable t) {
819            logIfEnabled(FQCN, Level.TRACE, marker, message, t);
820        }
821    
822        @Override
823        public void trace(final Message msg) {
824            logIfEnabled(FQCN, Level.TRACE, null, msg, null);
825        }
826    
827        @Override
828        public void trace(final Message msg, final Throwable t) {
829            logIfEnabled(FQCN, Level.TRACE, null, msg, t);
830        }
831    
832        @Override
833        public void trace(final Object message) {
834            logIfEnabled(FQCN, Level.TRACE, null, message, null);
835        }
836    
837        @Override
838        public void trace(final Object message, final Throwable t) {
839            logIfEnabled(FQCN, Level.TRACE, null, message, t);
840        }
841    
842        @Override
843        public void trace(final String message) {
844            logIfEnabled(FQCN, Level.TRACE, null, message, (Throwable) null);
845        }
846    
847        @Override
848        public void trace(final String message, final Object... params) {
849            logIfEnabled(FQCN, Level.TRACE, null, message, params);
850        }
851    
852        @Override
853        public void trace(final String message, final Throwable t) {
854            logIfEnabled(FQCN, Level.TRACE, null, message, t);
855        }
856    
857        @Override
858        public void warn(final Marker marker, final Message msg) {
859            logIfEnabled(FQCN, Level.WARN, marker, msg, null);
860        }
861    
862        @Override
863        public void warn(final Marker marker, final Message msg, final Throwable t) {
864            logIfEnabled(FQCN, Level.WARN, marker, msg, t);
865        }
866    
867        @Override
868        public void warn(final Marker marker, final Object message) {
869            logIfEnabled(FQCN, Level.WARN, marker, message, null);
870        }
871    
872        /* -- FIXME: this comment looks lost
873         * Instead of one single method with Object... declared the following methods explicitly specify parameters because
874         * they perform dramatically better than having the JVM convert them to an array.
875         */
876    
877        @Override
878        public void warn(final Marker marker, final Object message, final Throwable t) {
879            logIfEnabled(FQCN, Level.WARN, marker, message, t);
880        }
881    
882        @Override
883        public void warn(final Marker marker, final String message) {
884            logIfEnabled(FQCN, Level.WARN, marker, message, (Throwable) null);
885        }
886    
887        @Override
888        public void warn(final Marker marker, final String message, final Object... params) {
889            logIfEnabled(FQCN, Level.WARN, marker, message, params);
890        }
891    
892        @Override
893        public void warn(final Marker marker, final String message, final Throwable t) {
894            logIfEnabled(FQCN, Level.WARN, marker, message, t);
895        }
896    
897        @Override
898        public void warn(final Message msg) {
899            logIfEnabled(FQCN, Level.WARN, null, msg, null);
900        }
901    
902        @Override
903        public void warn(final Message msg, final Throwable t) {
904            logIfEnabled(FQCN, Level.WARN, null, msg, t);
905        }
906    
907        @Override
908        public void warn(final Object message) {
909            logIfEnabled(FQCN, Level.WARN, null, message, null);
910        }
911    
912        @Override
913        public void warn(final Object message, final Throwable t) {
914            logIfEnabled(FQCN, Level.WARN, null, message, t);
915        }
916    
917        @Override
918        public void warn(final String message) {
919            logIfEnabled(FQCN, Level.WARN, null, message, (Throwable) null);
920        }
921    
922        @Override
923        public void warn(final String message, final Object... params) {
924            logIfEnabled(FQCN, Level.WARN, null, message, params);
925        }
926    
927        @Override
928        public void warn(final String message, final Throwable t) {
929            logIfEnabled(FQCN, Level.WARN, null, message, t);
930        }
931    
932    }