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", or "error"). 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", or "error". 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     private static final int LOG_LEVEL_TRACE = LocationAwareLogger.TRACE_INT;
128     private static final int LOG_LEVEL_DEBUG = LocationAwareLogger.DEBUG_INT;
129     private static final int LOG_LEVEL_INFO = LocationAwareLogger.INFO_INT;
130     private static final int LOG_LEVEL_WARN = LocationAwareLogger.WARN_INT;
131     private static final int LOG_LEVEL_ERROR = LocationAwareLogger.ERROR_INT;
132 
133     private static boolean INITIALIZED = false;
134 
135     private static int DEFAULT_LOG_LEVEL = LOG_LEVEL_INFO;
136     private static boolean SHOW_DATE_TIME = false;
137     private static String DATE_TIME_FORMAT_STR = null;
138     private static DateFormat DATE_FORMATTER = null;
139     private static boolean SHOW_THREAD_NAME = true;
140     private static boolean SHOW_LOG_NAME = true;
141     private static boolean SHOW_SHORT_LOG_NAME = false;
142     private static String LOG_FILE = "System.err";
143     private static PrintStream TARGET_STREAM = null;
144     private static boolean LEVEL_IN_BRACKETS = false;
145     private static String WARN_LEVEL_STRING = "WARN";
146 
147     /** All system properties used by <code>SimpleLogger</code> start with this prefix */
148     public static final String SYSTEM_PREFIX = "org.slf4j.simpleLogger.";
149 
150     public static final String DEFAULT_LOG_LEVEL_KEY = SYSTEM_PREFIX + "defaultLogLevel";
151     public static final String SHOW_DATE_TIME_KEY = SYSTEM_PREFIX + "showDateTime";
152     public static final String DATE_TIME_FORMAT_KEY = SYSTEM_PREFIX + "dateTimeFormat";
153     public static final String SHOW_THREAD_NAME_KEY = SYSTEM_PREFIX + "showThreadName";
154     public static final String SHOW_LOG_NAME_KEY = SYSTEM_PREFIX + "showLogName";
155     public static final String SHOW_SHORT_LOG_NAME_KEY = SYSTEM_PREFIX + "showShortLogName";
156     public static final String LOG_FILE_KEY = SYSTEM_PREFIX + "logFile";
157     public static final String LEVEL_IN_BRACKETS_KEY = SYSTEM_PREFIX + "levelInBrackets";
158     public static final String WARN_LEVEL_STRING_KEY = SYSTEM_PREFIX + "warnLevelString";
159 
160     public static final String LOG_KEY_PREFIX = SYSTEM_PREFIX + "log.";
161 
162     private static String getStringProperty(String name) {
163         String prop = null;
164         try {
165             prop = System.getProperty(name);
166         } catch (SecurityException e) {
167             ; // Ignore
168         }
169         return (prop == null) ? SIMPLE_LOGGER_PROPS.getProperty(name) : prop;
170     }
171 
172     private static String getStringProperty(String name, String defaultValue) {
173         String prop = getStringProperty(name);
174         return (prop == null) ? defaultValue : prop;
175     }
176 
177     private static boolean getBooleanProperty(String name, boolean defaultValue) {
178         String prop = getStringProperty(name);
179         return (prop == null) ? defaultValue : "true".equalsIgnoreCase(prop);
180     }
181 
182     // Initialize class attributes.
183     // Load properties file, if found.
184     // Override with system properties.
185     static void init() {
186         if (INITIALIZED) {
187             return;
188         }
189         INITIALIZED = true;
190         loadProperties();
191 
192         String defaultLogLevelString = getStringProperty(DEFAULT_LOG_LEVEL_KEY, null);
193         if (defaultLogLevelString != null)
194             DEFAULT_LOG_LEVEL = stringToLevel(defaultLogLevelString);
195 
196         SHOW_LOG_NAME = getBooleanProperty(SHOW_LOG_NAME_KEY, SHOW_LOG_NAME);
197         SHOW_SHORT_LOG_NAME = getBooleanProperty(SHOW_SHORT_LOG_NAME_KEY, SHOW_SHORT_LOG_NAME);
198         SHOW_DATE_TIME = getBooleanProperty(SHOW_DATE_TIME_KEY, SHOW_DATE_TIME);
199         SHOW_THREAD_NAME = getBooleanProperty(SHOW_THREAD_NAME_KEY, SHOW_THREAD_NAME);
200         DATE_TIME_FORMAT_STR = getStringProperty(DATE_TIME_FORMAT_KEY, DATE_TIME_FORMAT_STR);
201         LEVEL_IN_BRACKETS = getBooleanProperty(LEVEL_IN_BRACKETS_KEY, LEVEL_IN_BRACKETS);
202         WARN_LEVEL_STRING = getStringProperty(WARN_LEVEL_STRING_KEY, WARN_LEVEL_STRING);
203 
204         LOG_FILE = getStringProperty(LOG_FILE_KEY, LOG_FILE);
205         TARGET_STREAM = computeTargetStream(LOG_FILE);
206 
207         if (DATE_TIME_FORMAT_STR != null) {
208             try {
209                 DATE_FORMATTER = new SimpleDateFormat(DATE_TIME_FORMAT_STR);
210             } catch (IllegalArgumentException e) {
211                 Util.report("Bad date format in " + CONFIGURATION_FILE + "; will output relative time", e);
212             }
213         }
214     }
215 
216     private static PrintStream computeTargetStream(String logFile) {
217         if ("System.err".equalsIgnoreCase(logFile))
218             return System.err;
219         else if ("System.out".equalsIgnoreCase(logFile)) {
220             return System.out;
221         } else {
222             try {
223                 FileOutputStream fos = new FileOutputStream(logFile);
224                 PrintStream printStream = new PrintStream(fos);
225                 return printStream;
226             } catch (FileNotFoundException e) {
227                 Util.report("Could not open [" + logFile + "]. Defaulting to System.err", e);
228                 return System.err;
229             }
230         }
231     }
232 
233     private static void loadProperties() {
234         // Add props from the resource simplelogger.properties
235         InputStream in = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
236             public InputStream run() {
237                 ClassLoader threadCL = Thread.currentThread().getContextClassLoader();
238                 if (threadCL != null) {
239                     return threadCL.getResourceAsStream(CONFIGURATION_FILE);
240                 } else {
241                     return ClassLoader.getSystemResourceAsStream(CONFIGURATION_FILE);
242                 }
243             }
244         });
245         if (null != in) {
246             try {
247                 SIMPLE_LOGGER_PROPS.load(in);
248                 in.close();
249             } catch (java.io.IOException e) {
250                 // ignored
251             }
252         }
253     }
254 
255     /** The current log level */
256     protected int currentLogLevel = LOG_LEVEL_INFO;
257     /** The short name of this simple log instance */
258     private transient String shortLogName = null;
259 
260     /**
261      * Package access allows only {@link SimpleLoggerFactory} to instantiate
262      * SimpleLogger instances.
263      */
264     SimpleLogger(String name) {
265         this.name = name;
266 
267         String levelString = recursivelyComputeLevelString();
268         if (levelString != null) {
269             this.currentLogLevel = stringToLevel(levelString);
270         } else {
271             this.currentLogLevel = DEFAULT_LOG_LEVEL;
272         }
273     }
274 
275     String recursivelyComputeLevelString() {
276         String tempName = name;
277         String levelString = null;
278         int indexOfLastDot = tempName.length();
279         while ((levelString == null) && (indexOfLastDot > -1)) {
280             tempName = tempName.substring(0, indexOfLastDot);
281             levelString = getStringProperty(LOG_KEY_PREFIX + tempName, null);
282             indexOfLastDot = String.valueOf(tempName).lastIndexOf(".");
283         }
284         return levelString;
285     }
286 
287     private static int stringToLevel(String levelStr) {
288         if ("trace".equalsIgnoreCase(levelStr)) {
289             return LOG_LEVEL_TRACE;
290         } else if ("debug".equalsIgnoreCase(levelStr)) {
291             return LOG_LEVEL_DEBUG;
292         } else if ("info".equalsIgnoreCase(levelStr)) {
293             return LOG_LEVEL_INFO;
294         } else if ("warn".equalsIgnoreCase(levelStr)) {
295             return LOG_LEVEL_WARN;
296         } else if ("error".equalsIgnoreCase(levelStr)) {
297             return LOG_LEVEL_ERROR;
298         }
299         // assume INFO by default
300         return LOG_LEVEL_INFO;
301     }
302 
303     /**
304      * This is our internal implementation for logging regular (non-parameterized)
305      * log messages.
306      *
307      * @param level   One of the LOG_LEVEL_XXX constants defining the log level
308      * @param message The message itself
309      * @param t       The exception whose stack trace should be logged
310      */
311     private void log(int level, String message, Throwable t) {
312         if (!isLevelEnabled(level)) {
313             return;
314         }
315 
316         StringBuilder buf = new StringBuilder(32);
317 
318         // Append date-time if so configured
319         if (SHOW_DATE_TIME) {
320             if (DATE_FORMATTER != null) {
321                 buf.append(getFormattedDate());
322                 buf.append(' ');
323             } else {
324                 buf.append(System.currentTimeMillis() - START_TIME);
325                 buf.append(' ');
326             }
327         }
328 
329         // Append current thread name if so configured
330         if (SHOW_THREAD_NAME) {
331             buf.append('[');
332             buf.append(Thread.currentThread().getName());
333             buf.append("] ");
334         }
335 
336         if (LEVEL_IN_BRACKETS)
337             buf.append('[');
338 
339         // Append a readable representation of the log level
340         switch (level) {
341         case LOG_LEVEL_TRACE:
342             buf.append("TRACE");
343             break;
344         case LOG_LEVEL_DEBUG:
345             buf.append("DEBUG");
346             break;
347         case LOG_LEVEL_INFO:
348             buf.append("INFO");
349             break;
350         case LOG_LEVEL_WARN:
351             buf.append(WARN_LEVEL_STRING);
352             break;
353         case LOG_LEVEL_ERROR:
354             buf.append("ERROR");
355             break;
356         }
357         if (LEVEL_IN_BRACKETS)
358             buf.append(']');
359         buf.append(' ');
360 
361         // Append the name of the log instance if so configured
362         if (SHOW_SHORT_LOG_NAME) {
363             if (shortLogName == null)
364                 shortLogName = computeShortName();
365             buf.append(String.valueOf(shortLogName)).append(" - ");
366         } else if (SHOW_LOG_NAME) {
367             buf.append(String.valueOf(name)).append(" - ");
368         }
369 
370         // Append the message
371         buf.append(message);
372 
373         write(buf, t);
374 
375     }
376 
377     void write(StringBuilder buf, Throwable t) {
378         TARGET_STREAM.println(buf.toString());
379         if (t != null) {
380             t.printStackTrace(TARGET_STREAM);
381         }
382         TARGET_STREAM.flush();
383     }
384 
385     private String getFormattedDate() {
386         Date now = new Date();
387         String dateText;
388         synchronized (DATE_FORMATTER) {
389             dateText = DATE_FORMATTER.format(now);
390         }
391         return dateText;
392     }
393 
394     private String computeShortName() {
395         return name.substring(name.lastIndexOf(".") + 1);
396     }
397 
398     /**
399      * For formatted messages, first substitute arguments and then log.
400      *
401      * @param level
402      * @param format
403      * @param arg1
404      * @param arg2
405      */
406     private void formatAndLog(int level, String format, Object arg1, Object arg2) {
407         if (!isLevelEnabled(level)) {
408             return;
409         }
410         FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
411         log(level, tp.getMessage(), tp.getThrowable());
412     }
413 
414     /**
415      * For formatted messages, first substitute arguments and then log.
416      *
417      * @param level
418      * @param format
419      * @param arguments a list of 3 ore more arguments
420      */
421     private void formatAndLog(int level, String format, Object... arguments) {
422         if (!isLevelEnabled(level)) {
423             return;
424         }
425         FormattingTuple tp = MessageFormatter.arrayFormat(format, arguments);
426         log(level, tp.getMessage(), tp.getThrowable());
427     }
428 
429     /**
430      * Is the given log level currently enabled?
431      *
432      * @param logLevel is this level enabled?
433      */
434     protected boolean isLevelEnabled(int logLevel) {
435         // log level are numerically ordered so can use simple numeric
436         // comparison
437         return (logLevel >= currentLogLevel);
438     }
439 
440     /** Are {@code trace} messages currently enabled? */
441     public boolean isTraceEnabled() {
442         return isLevelEnabled(LOG_LEVEL_TRACE);
443     }
444 
445     /**
446      * A simple implementation which logs messages of level TRACE according
447      * to the format outlined above.
448      */
449     public void trace(String msg) {
450         log(LOG_LEVEL_TRACE, msg, null);
451     }
452 
453     /**
454      * Perform single parameter substitution before logging the message of level
455      * TRACE according to the format outlined above.
456      */
457     public void trace(String format, Object param1) {
458         formatAndLog(LOG_LEVEL_TRACE, format, param1, null);
459     }
460 
461     /**
462      * Perform double parameter substitution before logging the message of level
463      * TRACE according to the format outlined above.
464      */
465     public void trace(String format, Object param1, Object param2) {
466         formatAndLog(LOG_LEVEL_TRACE, format, param1, param2);
467     }
468 
469     /**
470      * Perform double parameter substitution before logging the message of level
471      * TRACE according to the format outlined above.
472      */
473     public void trace(String format, Object... argArray) {
474         formatAndLog(LOG_LEVEL_TRACE, format, argArray);
475     }
476 
477     /** Log a message of level TRACE, including an exception. */
478     public void trace(String msg, Throwable t) {
479         log(LOG_LEVEL_TRACE, msg, t);
480     }
481 
482     /** Are {@code debug} messages currently enabled? */
483     public boolean isDebugEnabled() {
484         return isLevelEnabled(LOG_LEVEL_DEBUG);
485     }
486 
487     /**
488      * A simple implementation which logs messages of level DEBUG according
489      * to the format outlined above.
490      */
491     public void debug(String msg) {
492         log(LOG_LEVEL_DEBUG, msg, null);
493     }
494 
495     /**
496      * Perform single parameter substitution before logging the message of level
497      * DEBUG according to the format outlined above.
498      */
499     public void debug(String format, Object param1) {
500         formatAndLog(LOG_LEVEL_DEBUG, format, param1, null);
501     }
502 
503     /**
504      * Perform double parameter substitution before logging the message of level
505      * DEBUG according to the format outlined above.
506      */
507     public void debug(String format, Object param1, Object param2) {
508         formatAndLog(LOG_LEVEL_DEBUG, format, param1, param2);
509     }
510 
511     /**
512      * Perform double parameter substitution before logging the message of level
513      * DEBUG according to the format outlined above.
514      */
515     public void debug(String format, Object... argArray) {
516         formatAndLog(LOG_LEVEL_DEBUG, format, argArray);
517     }
518 
519     /** Log a message of level DEBUG, including an exception. */
520     public void debug(String msg, Throwable t) {
521         log(LOG_LEVEL_DEBUG, msg, t);
522     }
523 
524     /** Are {@code info} messages currently enabled? */
525     public boolean isInfoEnabled() {
526         return isLevelEnabled(LOG_LEVEL_INFO);
527     }
528 
529     /**
530      * A simple implementation which logs messages of level INFO according
531      * to the format outlined above.
532      */
533     public void info(String msg) {
534         log(LOG_LEVEL_INFO, msg, null);
535     }
536 
537     /**
538      * Perform single parameter substitution before logging the message of level
539      * INFO according to the format outlined above.
540      */
541     public void info(String format, Object arg) {
542         formatAndLog(LOG_LEVEL_INFO, format, arg, null);
543     }
544 
545     /**
546      * Perform double parameter substitution before logging the message of level
547      * INFO according to the format outlined above.
548      */
549     public void info(String format, Object arg1, Object arg2) {
550         formatAndLog(LOG_LEVEL_INFO, format, arg1, arg2);
551     }
552 
553     /**
554      * Perform double parameter substitution before logging the message of level
555      * INFO according to the format outlined above.
556      */
557     public void info(String format, Object... argArray) {
558         formatAndLog(LOG_LEVEL_INFO, format, argArray);
559     }
560 
561     /** Log a message of level INFO, including an exception. */
562     public void info(String msg, Throwable t) {
563         log(LOG_LEVEL_INFO, msg, t);
564     }
565 
566     /** Are {@code warn} messages currently enabled? */
567     public boolean isWarnEnabled() {
568         return isLevelEnabled(LOG_LEVEL_WARN);
569     }
570 
571     /**
572      * A simple implementation which always logs messages of level WARN according
573      * to the format outlined above.
574      */
575     public void warn(String msg) {
576         log(LOG_LEVEL_WARN, msg, null);
577     }
578 
579     /**
580      * Perform single parameter substitution before logging the message of level
581      * WARN according to the format outlined above.
582      */
583     public void warn(String format, Object arg) {
584         formatAndLog(LOG_LEVEL_WARN, format, arg, null);
585     }
586 
587     /**
588      * Perform double parameter substitution before logging the message of level
589      * WARN according to the format outlined above.
590      */
591     public void warn(String format, Object arg1, Object arg2) {
592         formatAndLog(LOG_LEVEL_WARN, format, arg1, arg2);
593     }
594 
595     /**
596      * Perform double parameter substitution before logging the message of level
597      * WARN according to the format outlined above.
598      */
599     public void warn(String format, Object... argArray) {
600         formatAndLog(LOG_LEVEL_WARN, format, argArray);
601     }
602 
603     /** Log a message of level WARN, including an exception. */
604     public void warn(String msg, Throwable t) {
605         log(LOG_LEVEL_WARN, msg, t);
606     }
607 
608     /** Are {@code error} messages currently enabled? */
609     public boolean isErrorEnabled() {
610         return isLevelEnabled(LOG_LEVEL_ERROR);
611     }
612 
613     /**
614      * A simple implementation which always logs messages of level ERROR according
615      * to the format outlined above.
616      */
617     public void error(String msg) {
618         log(LOG_LEVEL_ERROR, msg, null);
619     }
620 
621     /**
622      * Perform single parameter substitution before logging the message of level
623      * ERROR according to the format outlined above.
624      */
625     public void error(String format, Object arg) {
626         formatAndLog(LOG_LEVEL_ERROR, format, arg, null);
627     }
628 
629     /**
630      * Perform double parameter substitution before logging the message of level
631      * ERROR according to the format outlined above.
632      */
633     public void error(String format, Object arg1, Object arg2) {
634         formatAndLog(LOG_LEVEL_ERROR, format, arg1, arg2);
635     }
636 
637     /**
638      * Perform double parameter substitution before logging the message of level
639      * ERROR according to the format outlined above.
640      */
641     public void error(String format, Object... argArray) {
642         formatAndLog(LOG_LEVEL_ERROR, format, argArray);
643     }
644 
645     /** Log a message of level ERROR, including an exception. */
646     public void error(String msg, Throwable t) {
647         log(LOG_LEVEL_ERROR, msg, t);
648     }
649 
650     public void log(LoggingEvent event) {
651         int levelInt = event.getLevel().toInt();
652 
653         if (!isLevelEnabled(levelInt)) {
654             return;
655         }
656         FormattingTuple tp = MessageFormatter.arrayFormat(event.getMessage(), event.getArgumentArray(), event.getThrowable());
657         log(levelInt, tp.getMessage(), event.getThrowable());
658     }
659 
660 }