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