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