View Javadoc
1   /**
2    * Copyright (c) 2004-2012 QOS.ch
3    * All rights reserved.
4    *
5    * Permission is hereby granted, free of charge, to any person obtaining
6    * a copy of this software and associated documentation files (the
7    * "Software"), to  deal in  the Software without  restriction, including
8    * without limitation  the rights to  use, copy, modify,  merge, publish,
9    * distribute,  sublicense, and/or sell  copies of  the Software,  and to
10   * permit persons to whom the Software  is furnished to do so, subject to
11   * the following conditions:
12   *
13   * The  above  copyright  notice  and  this permission  notice  shall  be
14   * included in all copies or substantial portions of the Software.
15   *
16   * THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
17   * EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
18   * MERCHANTABILITY,    FITNESS    FOR    A   PARTICULAR    PURPOSE    AND
19   * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20   * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21   * OF CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT OF OR IN CONNECTION
22   * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23   *
24   */
25  package org.slf4j.impl;
26  
27  import java.io.FileNotFoundException;
28  import java.io.FileOutputStream;
29  import java.io.InputStream;
30  import java.io.PrintStream;
31  import java.security.AccessController;
32  import java.security.PrivilegedAction;
33  import java.text.DateFormat;
34  import java.text.SimpleDateFormat;
35  import java.util.Date;
36  import java.util.Properties;
37  
38  import org.slf4j.Logger;
39  import org.slf4j.event.LoggingEvent;
40  import org.slf4j.helpers.FormattingTuple;
41  import org.slf4j.helpers.MarkerIgnoringBase;
42  import org.slf4j.helpers.MessageFormatter;
43  import org.slf4j.helpers.Util;
44  import org.slf4j.spi.LocationAwareLogger;
45  
46  /**
47   * <p>Simple implementation of {@link Logger} that sends all enabled log messages,
48   * for all defined loggers, to the console ({@code System.err}).
49   * The following system properties are supported to configure the behavior of this logger:</p>
50   *
51   * <ul>
52   * <li><code>org.slf4j.simpleLogger.logFile</code> - The output target which can be the <em>path</em> to a file, or
53   * the special values "System.out" and "System.err". Default is "System.err".
54   *
55   * <li><code>org.slf4j.simpleLogger.defaultLogLevel</code> - Default log level for all instances of SimpleLogger.
56   * Must be one of ("trace", "debug", "info", "warn", "error" or "off"). If not specified, defaults to "info". </li>
57   *
58   * <li><code>org.slf4j.simpleLogger.log.<em>a.b.c</em></code> - Logging detail level for a SimpleLogger instance
59   * named "a.b.c". Right-side value must be one of "trace", "debug", "info", "warn", "error" or "off". When a SimpleLogger
60   * named "a.b.c" is initialized, its level is assigned from this property. If unspecified, the level of nearest parent
61   * logger will be used, and if none is set, then the value specified by
62   * <code>org.slf4j.simpleLogger.defaultLogLevel</code> will be used.</li>
63   *
64   * <li><code>org.slf4j.simpleLogger.showDateTime</code> - Set to <code>true</code> if you want the current date and
65   * time to be included in output messages. Default is <code>false</code></li>
66   *
67   * <li><code>org.slf4j.simpleLogger.dateTimeFormat</code> - The date and time format to be used in the output messages.
68   * The pattern describing the date and time format is defined by
69   * <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html"><code>SimpleDateFormat</code></a>.
70   * If the format is not specified or is invalid, the number of milliseconds since start up will be output. </li>
71   *
72   * <li><code>org.slf4j.simpleLogger.showThreadName</code> -Set to <code>true</code> if you want to output the current
73   * thread name. Defaults to <code>true</code>.</li>
74   *
75   * <li><code>org.slf4j.simpleLogger.showLogName</code> - Set to <code>true</code> if you want the Logger instance name
76   * to be included in output messages. Defaults to <code>true</code>.</li>
77   *
78   * <li><code>org.slf4j.simpleLogger.showShortLogName</code> - Set to <code>true</code> if you want the last component
79   * of the name to be included in output messages. Defaults to <code>false</code>.</li>
80   *
81   * <li><code>org.slf4j.simpleLogger.levelInBrackets</code> - Should the level string be output in brackets? Defaults
82   * to <code>false</code>.</li>
83   *
84   * <li><code>org.slf4j.simpleLogger.warnLevelString</code> - The string value output for the warn level. Defaults
85   * to <code>WARN</code>.</li>
86  
87   * </ul>
88   *
89   * <p>In addition to looking for system properties with the names specified above, this implementation also checks for
90   * a class loader resource named <code>"simplelogger.properties"</code>, and includes any matching definitions
91   * from this resource (if it exists).</p>
92   *
93   * <p>With no configuration, the default output includes the relative time in milliseconds, thread name, the level,
94   * logger name, and the message followed by the line separator for the host.  In log4j terms it amounts to the "%r [%t]
95   * %level %logger - %m%n" pattern. </p>
96   * <p>Sample output follows.</p>
97   * <pre>
98   * 176 [main] INFO examples.Sort - Populating an array of 2 elements in reverse order.
99   * 225 [main] INFO examples.SortAlgo - Entered the sort method.
100  * 304 [main] INFO examples.SortAlgo - Dump of integer array:
101  * 317 [main] INFO examples.SortAlgo - Element [0] = 0
102  * 331 [main] INFO examples.SortAlgo - Element [1] = 1
103  * 343 [main] INFO examples.Sort - The next log statement should be an error message.
104  * 346 [main] ERROR examples.SortAlgo - Tried to dump an uninitialized array.
105  *   at org.log4j.examples.SortAlgo.dump(SortAlgo.java:58)
106  *   at org.log4j.examples.Sort.main(Sort.java:64)
107  * 467 [main] INFO  examples.Sort - Exiting main method.
108  * </pre>
109  *
110  * <p>This implementation is heavily inspired by
111  * <a href="http://commons.apache.org/logging/">Apache Commons Logging</a>'s SimpleLog.</p>
112  *
113  * @author Ceki G&uuml;lc&uuml;
114  * @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
115  * @author Rod Waldhoff
116  * @author Robert Burrell Donkin
117  * @author C&eacute;drik LIME
118  */
119 public class SimpleLogger extends MarkerIgnoringBase {
120 
121     private static final long serialVersionUID = -632788891211436180L;
122     private static final String CONFIGURATION_FILE = "simplelogger.properties";
123 
124     private static long START_TIME = System.currentTimeMillis();
125     private static final Properties SIMPLE_LOGGER_PROPS = new Properties();
126 
127     protected static final int LOG_LEVEL_TRACE = LocationAwareLogger.TRACE_INT;
128     protected static final int LOG_LEVEL_DEBUG = LocationAwareLogger.DEBUG_INT;
129     protected static final int LOG_LEVEL_INFO = LocationAwareLogger.INFO_INT;
130     protected static final int LOG_LEVEL_WARN = LocationAwareLogger.WARN_INT;
131     protected static final int LOG_LEVEL_ERROR = LocationAwareLogger.ERROR_INT;
132     // The OFF level can only be used in configuration files to disable logging. It has
133     // no printing method associated with it in o.s.Logger interface.
134     protected static final int LOG_LEVEL_OFF = LOG_LEVEL_ERROR + 10;
135 
136     private static boolean INITIALIZED = false;
137 
138     private static int DEFAULT_LOG_LEVEL = LOG_LEVEL_INFO;
139     private static boolean SHOW_DATE_TIME = false;
140     private static String DATE_TIME_FORMAT_STR = null;
141     private static DateFormat DATE_FORMATTER = null;
142     private static boolean SHOW_THREAD_NAME = true;
143     private static boolean SHOW_LOG_NAME = true;
144     private static boolean SHOW_SHORT_LOG_NAME = false;
145     private static String LOG_FILE = "System.err";
146     private static PrintStream TARGET_STREAM = null;
147     private static boolean LEVEL_IN_BRACKETS = false;
148     private static String WARN_LEVEL_STRING = "WARN";
149 
150     /** All system properties used by <code>SimpleLogger</code> start with this prefix */
151     public static final String SYSTEM_PREFIX = "org.slf4j.simpleLogger.";
152 
153     public static final String DEFAULT_LOG_LEVEL_KEY = SYSTEM_PREFIX + "defaultLogLevel";
154     public static final String SHOW_DATE_TIME_KEY = SYSTEM_PREFIX + "showDateTime";
155     public static final String DATE_TIME_FORMAT_KEY = SYSTEM_PREFIX + "dateTimeFormat";
156     public static final String SHOW_THREAD_NAME_KEY = SYSTEM_PREFIX + "showThreadName";
157     public static final String SHOW_LOG_NAME_KEY = SYSTEM_PREFIX + "showLogName";
158     public static final String SHOW_SHORT_LOG_NAME_KEY = SYSTEM_PREFIX + "showShortLogName";
159     public static final String LOG_FILE_KEY = SYSTEM_PREFIX + "logFile";
160     public static final String LEVEL_IN_BRACKETS_KEY = SYSTEM_PREFIX + "levelInBrackets";
161     public static final String WARN_LEVEL_STRING_KEY = SYSTEM_PREFIX + "warnLevelString";
162 
163     public static final String LOG_KEY_PREFIX = SYSTEM_PREFIX + "log.";
164 
165     private static String getStringProperty(String name) {
166         String prop = null;
167         try {
168             prop = System.getProperty(name);
169         } catch (SecurityException e) {
170             ; // Ignore
171         }
172         return (prop == null) ? SIMPLE_LOGGER_PROPS.getProperty(name) : prop;
173     }
174 
175     private static String getStringProperty(String name, String defaultValue) {
176         String prop = getStringProperty(name);
177         return (prop == null) ? defaultValue : prop;
178     }
179 
180     private static boolean getBooleanProperty(String name, boolean defaultValue) {
181         String prop = getStringProperty(name);
182         return (prop == null) ? defaultValue : "true".equalsIgnoreCase(prop);
183     }
184 
185     static void lazyInit() {
186         if (INITIALIZED) {
187             return;
188         }
189         INITIALIZED = true;
190         init();
191     }
192     
193     static void init() {
194         loadProperties();
195 
196         String defaultLogLevelString = getStringProperty(DEFAULT_LOG_LEVEL_KEY, null);
197         if (defaultLogLevelString != null)
198             DEFAULT_LOG_LEVEL = stringToLevel(defaultLogLevelString);
199 
200         SHOW_LOG_NAME = getBooleanProperty(SHOW_LOG_NAME_KEY, SHOW_LOG_NAME);
201         SHOW_SHORT_LOG_NAME = getBooleanProperty(SHOW_SHORT_LOG_NAME_KEY, SHOW_SHORT_LOG_NAME);
202         SHOW_DATE_TIME = getBooleanProperty(SHOW_DATE_TIME_KEY, SHOW_DATE_TIME);
203         SHOW_THREAD_NAME = getBooleanProperty(SHOW_THREAD_NAME_KEY, SHOW_THREAD_NAME);
204         DATE_TIME_FORMAT_STR = getStringProperty(DATE_TIME_FORMAT_KEY, DATE_TIME_FORMAT_STR);
205         LEVEL_IN_BRACKETS = getBooleanProperty(LEVEL_IN_BRACKETS_KEY, LEVEL_IN_BRACKETS);
206         WARN_LEVEL_STRING = getStringProperty(WARN_LEVEL_STRING_KEY, WARN_LEVEL_STRING);
207 
208         LOG_FILE = getStringProperty(LOG_FILE_KEY, LOG_FILE);
209         TARGET_STREAM = computeTargetStream(LOG_FILE);
210 
211         if (DATE_TIME_FORMAT_STR != null) {
212             try {
213                 DATE_FORMATTER = new SimpleDateFormat(DATE_TIME_FORMAT_STR);
214             } catch (IllegalArgumentException e) {
215                 Util.report("Bad date format in " + CONFIGURATION_FILE + "; will output relative time", e);
216             }
217         }
218     }
219 
220     private static PrintStream computeTargetStream(String logFile) {
221         if ("System.err".equalsIgnoreCase(logFile))
222             return System.err;
223         else if ("System.out".equalsIgnoreCase(logFile)) {
224             return System.out;
225         } else {
226             try {
227                 FileOutputStream fos = new FileOutputStream(logFile);
228                 PrintStream printStream = new PrintStream(fos);
229                 return printStream;
230             } catch (FileNotFoundException e) {
231                 Util.report("Could not open [" + logFile + "]. Defaulting to System.err", e);
232                 return System.err;
233             }
234         }
235     }
236 
237     private static void loadProperties() {
238         // Add props from the resource simplelogger.properties
239         InputStream in = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
240             public InputStream run() {
241                 ClassLoader threadCL = Thread.currentThread().getContextClassLoader();
242                 if (threadCL != null) {
243                     return threadCL.getResourceAsStream(CONFIGURATION_FILE);
244                 } else {
245                     return ClassLoader.getSystemResourceAsStream(CONFIGURATION_FILE);
246                 }
247             }
248         });
249         if (null != in) {
250             try {
251                 SIMPLE_LOGGER_PROPS.load(in);
252             } catch (java.io.IOException e) {
253                 // ignored
254             } finally {
255                 try {
256                     in.close();
257                 } catch (java.io.IOException e) {
258                     // ignored
259                 }
260             }
261         }
262     }
263 
264     /** The current log level */
265     protected int currentLogLevel = LOG_LEVEL_INFO;
266     /** The short name of this simple log instance */
267     private transient String shortLogName = null;
268 
269     /**
270      * Package access allows only {@link SimpleLoggerFactory} to instantiate
271      * SimpleLogger instances.
272      */
273     SimpleLogger(String name) {
274         this.name = name;
275 
276         String levelString = recursivelyComputeLevelString();
277         if (levelString != null) {
278             this.currentLogLevel = stringToLevel(levelString);
279         } else {
280             this.currentLogLevel = DEFAULT_LOG_LEVEL;
281         }
282     }
283 
284     String recursivelyComputeLevelString() {
285         String tempName = name;
286         String levelString = null;
287         int indexOfLastDot = tempName.length();
288         while ((levelString == null) && (indexOfLastDot > -1)) {
289             tempName = tempName.substring(0, indexOfLastDot);
290             levelString = getStringProperty(LOG_KEY_PREFIX + tempName, null);
291             indexOfLastDot = String.valueOf(tempName).lastIndexOf(".");
292         }
293         return levelString;
294     }
295 
296     private static int stringToLevel(String levelStr) {
297         if ("trace".equalsIgnoreCase(levelStr)) {
298             return LOG_LEVEL_TRACE;
299         } else if ("debug".equalsIgnoreCase(levelStr)) {
300             return LOG_LEVEL_DEBUG;
301         } else if ("info".equalsIgnoreCase(levelStr)) {
302             return LOG_LEVEL_INFO;
303         } else if ("warn".equalsIgnoreCase(levelStr)) {
304             return LOG_LEVEL_WARN;
305         } else if ("error".equalsIgnoreCase(levelStr)) {
306             return LOG_LEVEL_ERROR;
307         } else if ("off".equalsIgnoreCase(levelStr)) {
308             return LOG_LEVEL_OFF;
309         }
310         // assume INFO by default
311         return LOG_LEVEL_INFO;
312     }
313 
314     /**
315      * This is our internal implementation for logging regular (non-parameterized)
316      * log messages.
317      *
318      * @param level   One of the LOG_LEVEL_XXX constants defining the log level
319      * @param message The message itself
320      * @param t       The exception whose stack trace should be logged
321      */
322     private void log(int level, String message, Throwable t) {
323         if (!isLevelEnabled(level)) {
324             return;
325         }
326 
327         StringBuilder buf = new StringBuilder(32);
328 
329         // Append date-time if so configured
330         if (SHOW_DATE_TIME) {
331             if (DATE_FORMATTER != null) {
332                 buf.append(getFormattedDate());
333                 buf.append(' ');
334             } else {
335                 buf.append(System.currentTimeMillis() - START_TIME);
336                 buf.append(' ');
337             }
338         }
339 
340         // Append current thread name if so configured
341         if (SHOW_THREAD_NAME) {
342             buf.append('[');
343             buf.append(Thread.currentThread().getName());
344             buf.append("] ");
345         }
346 
347         if (LEVEL_IN_BRACKETS)
348             buf.append('[');
349 
350         // Append a readable representation of the log level
351         buf.append(renderLevel(level));
352         if (LEVEL_IN_BRACKETS)
353             buf.append(']');
354         buf.append(' ');
355 
356         // Append the name of the log instance if so configured
357         if (SHOW_SHORT_LOG_NAME) {
358             if (shortLogName == null)
359                 shortLogName = computeShortName();
360             buf.append(String.valueOf(shortLogName)).append(" - ");
361         } else if (SHOW_LOG_NAME) {
362             buf.append(String.valueOf(name)).append(" - ");
363         }
364 
365         // Append the message
366         buf.append(message);
367 
368         write(buf, t);
369 
370     }
371 
372     void write(StringBuilder buf, Throwable t) {
373         TARGET_STREAM.println(buf.toString());
374         if (t != null) {
375             t.printStackTrace(TARGET_STREAM);
376         }
377         TARGET_STREAM.flush();
378     }
379 
380     private String getFormattedDate() {
381         Date now = new Date();
382         String dateText;
383         synchronized (DATE_FORMATTER) {
384             dateText = DATE_FORMATTER.format(now);
385         }
386         return dateText;
387     }
388 
389     private String computeShortName() {
390         return name.substring(name.lastIndexOf(".") + 1);
391     }
392 
393     /**
394      * For formatted messages, first substitute arguments and then log.
395      *
396      * @param level
397      * @param format
398      * @param arg1
399      * @param arg2
400      */
401     private void formatAndLog(int level, String format, Object arg1, Object arg2) {
402         if (!isLevelEnabled(level)) {
403             return;
404         }
405         FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
406         log(level, tp.getMessage(), tp.getThrowable());
407     }
408 
409     /**
410      * For formatted messages, first substitute arguments and then log.
411      *
412      * @param level
413      * @param format
414      * @param arguments a list of 3 ore more arguments
415      */
416     private void formatAndLog(int level, String format, Object... arguments) {
417         if (!isLevelEnabled(level)) {
418             return;
419         }
420         FormattingTuple tp = MessageFormatter.arrayFormat(format, arguments);
421         log(level, tp.getMessage(), tp.getThrowable());
422     }
423 
424     /**
425      * Is the given log level currently enabled?
426      *
427      * @param logLevel is this level enabled?
428      */
429     protected boolean isLevelEnabled(int logLevel) {
430         // log level are numerically ordered so can use simple numeric
431         // comparison
432         return (logLevel >= currentLogLevel);
433     }
434 
435     /** Are {@code trace} messages currently enabled? */
436     public boolean isTraceEnabled() {
437         return isLevelEnabled(LOG_LEVEL_TRACE);
438     }
439 
440     /**
441      * A simple implementation which logs messages of level TRACE according
442      * to the format outlined above.
443      */
444     public void trace(String msg) {
445         log(LOG_LEVEL_TRACE, msg, null);
446     }
447 
448     /**
449      * Perform single parameter substitution before logging the message of level
450      * TRACE according to the format outlined above.
451      */
452     public void trace(String format, Object param1) {
453         formatAndLog(LOG_LEVEL_TRACE, format, param1, null);
454     }
455 
456     /**
457      * Perform double parameter substitution before logging the message of level
458      * TRACE according to the format outlined above.
459      */
460     public void trace(String format, Object param1, Object param2) {
461         formatAndLog(LOG_LEVEL_TRACE, format, param1, param2);
462     }
463 
464     /**
465      * Perform double parameter substitution before logging the message of level
466      * TRACE according to the format outlined above.
467      */
468     public void trace(String format, Object... argArray) {
469         formatAndLog(LOG_LEVEL_TRACE, format, argArray);
470     }
471 
472     /** Log a message of level TRACE, including an exception. */
473     public void trace(String msg, Throwable t) {
474         log(LOG_LEVEL_TRACE, msg, t);
475     }
476 
477     /** Are {@code debug} messages currently enabled? */
478     public boolean isDebugEnabled() {
479         return isLevelEnabled(LOG_LEVEL_DEBUG);
480     }
481 
482     /**
483      * A simple implementation which logs messages of level DEBUG according
484      * to the format outlined above.
485      */
486     public void debug(String msg) {
487         log(LOG_LEVEL_DEBUG, msg, null);
488     }
489 
490     /**
491      * Perform single parameter substitution before logging the message of level
492      * DEBUG according to the format outlined above.
493      */
494     public void debug(String format, Object param1) {
495         formatAndLog(LOG_LEVEL_DEBUG, format, param1, null);
496     }
497 
498     /**
499      * Perform double parameter substitution before logging the message of level
500      * DEBUG according to the format outlined above.
501      */
502     public void debug(String format, Object param1, Object param2) {
503         formatAndLog(LOG_LEVEL_DEBUG, format, param1, param2);
504     }
505 
506     /**
507      * Perform double parameter substitution before logging the message of level
508      * DEBUG according to the format outlined above.
509      */
510     public void debug(String format, Object... argArray) {
511         formatAndLog(LOG_LEVEL_DEBUG, format, argArray);
512     }
513 
514     /** Log a message of level DEBUG, including an exception. */
515     public void debug(String msg, Throwable t) {
516         log(LOG_LEVEL_DEBUG, msg, t);
517     }
518 
519     /** Are {@code info} messages currently enabled? */
520     public boolean isInfoEnabled() {
521         return isLevelEnabled(LOG_LEVEL_INFO);
522     }
523 
524     /**
525      * A simple implementation which logs messages of level INFO according
526      * to the format outlined above.
527      */
528     public void info(String msg) {
529         log(LOG_LEVEL_INFO, msg, null);
530     }
531 
532     /**
533      * Perform single parameter substitution before logging the message of level
534      * INFO according to the format outlined above.
535      */
536     public void info(String format, Object arg) {
537         formatAndLog(LOG_LEVEL_INFO, format, arg, null);
538     }
539 
540     /**
541      * Perform double parameter substitution before logging the message of level
542      * INFO according to the format outlined above.
543      */
544     public void info(String format, Object arg1, Object arg2) {
545         formatAndLog(LOG_LEVEL_INFO, format, arg1, arg2);
546     }
547 
548     /**
549      * Perform double parameter substitution before logging the message of level
550      * INFO according to the format outlined above.
551      */
552     public void info(String format, Object... argArray) {
553         formatAndLog(LOG_LEVEL_INFO, format, argArray);
554     }
555 
556     /** Log a message of level INFO, including an exception. */
557     public void info(String msg, Throwable t) {
558         log(LOG_LEVEL_INFO, msg, t);
559     }
560 
561     /** Are {@code warn} messages currently enabled? */
562     public boolean isWarnEnabled() {
563         return isLevelEnabled(LOG_LEVEL_WARN);
564     }
565 
566     /**
567      * A simple implementation which always logs messages of level WARN according
568      * to the format outlined above.
569      */
570     public void warn(String msg) {
571         log(LOG_LEVEL_WARN, msg, null);
572     }
573 
574     /**
575      * Perform single parameter substitution before logging the message of level
576      * WARN according to the format outlined above.
577      */
578     public void warn(String format, Object arg) {
579         formatAndLog(LOG_LEVEL_WARN, format, arg, null);
580     }
581 
582     /**
583      * Perform double parameter substitution before logging the message of level
584      * WARN according to the format outlined above.
585      */
586     public void warn(String format, Object arg1, Object arg2) {
587         formatAndLog(LOG_LEVEL_WARN, format, arg1, arg2);
588     }
589 
590     /**
591      * Perform double parameter substitution before logging the message of level
592      * WARN according to the format outlined above.
593      */
594     public void warn(String format, Object... argArray) {
595         formatAndLog(LOG_LEVEL_WARN, format, argArray);
596     }
597 
598     /** Log a message of level WARN, including an exception. */
599     public void warn(String msg, Throwable t) {
600         log(LOG_LEVEL_WARN, msg, t);
601     }
602 
603     /** Are {@code error} messages currently enabled? */
604     public boolean isErrorEnabled() {
605         return isLevelEnabled(LOG_LEVEL_ERROR);
606     }
607 
608     /**
609      * A simple implementation which always logs messages of level ERROR according
610      * to the format outlined above.
611      */
612     public void error(String msg) {
613         log(LOG_LEVEL_ERROR, msg, null);
614     }
615 
616     /**
617      * Perform single parameter substitution before logging the message of level
618      * ERROR according to the format outlined above.
619      */
620     public void error(String format, Object arg) {
621         formatAndLog(LOG_LEVEL_ERROR, format, arg, null);
622     }
623 
624     /**
625      * Perform double parameter substitution before logging the message of level
626      * ERROR according to the format outlined above.
627      */
628     public void error(String format, Object arg1, Object arg2) {
629         formatAndLog(LOG_LEVEL_ERROR, format, arg1, arg2);
630     }
631 
632     /**
633      * Perform double parameter substitution before logging the message of level
634      * ERROR according to the format outlined above.
635      */
636     public void error(String format, Object... argArray) {
637         formatAndLog(LOG_LEVEL_ERROR, format, argArray);
638     }
639 
640     /** Log a message of level ERROR, including an exception. */
641     public void error(String msg, Throwable t) {
642         log(LOG_LEVEL_ERROR, msg, t);
643     }
644 
645     public void log(LoggingEvent event) {
646         int levelInt = event.getLevel().toInt();
647 
648         if (!isLevelEnabled(levelInt)) {
649             return;
650         }
651         FormattingTuple tp = MessageFormatter.arrayFormat(event.getMessage(), event.getArgumentArray(), event.getThrowable());
652         log(levelInt, tp.getMessage(), event.getThrowable());
653     }
654 
655   protected void renderThrowable(Throwable t, PrintStream stream) {}
656   protected String renderLevel(int level) { return ""; }
657 }