org.slf4j.impl
Class SimpleLogger

java.lang.Object
  extended by org.slf4j.helpers.MarkerIgnoringBase
      extended by org.slf4j.impl.SimpleLogger
All Implemented Interfaces:
Serializable, Logger

public class SimpleLogger
extends MarkerIgnoringBase

Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to the console (System.err). The following system properties are supported to configure the behavior of this logger:

In addition to looking for system properties with the names specified above, this implementation also checks for a class loader resource named "simplelogger.properties", and includes any matching definitions from this resource (if it exists).

With no configuration, the default output includes the relative time in milliseconds, thread name, the level, logger name, and the message followed by the line separator for the host. In log4j terms it amounts to the "%r [%t] %level %logger - %m%n" pattern.

Sample output follows.

 176 [main] INFO examples.Sort - Populating an array of 2 elements in reverse order.
 225 [main] INFO examples.SortAlgo - Entered the sort method.
 304 [main] INFO examples.SortAlgo - Dump of integer array:
 317 [main] INFO examples.SortAlgo - Element [0] = 0
 331 [main] INFO examples.SortAlgo - Element [1] = 1
 343 [main] INFO examples.Sort - The next log statement should be an error message.
 346 [main] ERROR examples.SortAlgo - Tried to dump an uninitialized array.
   at org.log4j.examples.SortAlgo.dump(SortAlgo.java:58)
   at org.log4j.examples.Sort.main(Sort.java:64)
 467 [main] INFO  examples.Sort - Exiting main method.
 

This implementation is heavily inspired by Apache Commons Logging's SimpleLog.

Author:
Ceki Gülcü, Scott Sanders, Rod Waldhoff, Robert Burrell Donkin, Cédrik LIME
See Also:
Serialized Form

Field Summary
protected  int currentLogLevel
          The current log level
static String DATE_TIME_FORMAT_KEY
           
static String DEFAULT_LOG_LEVEL_KEY
           
static String LEVEL_IN_BRACKETS_KEY
           
static String LOG_FILE_KEY
           
static String LOG_KEY_PREFIX
           
protected  String name
           
static String SHOW_DATE_TIME_KEY
           
static String SHOW_LOG_NAME_KEY
           
static String SHOW_SHORT_LOG_NAME_KEY
           
static String SHOW_THREAD_NAME_KEY
           
static String SYSTEM_PREFIX
          All system properties used by SimpleLogger start with this prefix
static String WARN_LEVEL_STRING_KEY
           
 
Fields inherited from interface org.slf4j.Logger
ROOT_LOGGER_NAME
 
Method Summary
 void debug(String msg)
          A simple implementation which logs messages of level DEBUG according to the format outlined above.
 void debug(String format, Object... argArray)
          Perform double parameter substitution before logging the message of level DEBUG according to the format outlined above.
 void debug(String format, Object param1)
          Perform single parameter substitution before logging the message of level DEBUG according to the format outlined above.
 void debug(String format, Object param1, Object param2)
          Perform double parameter substitution before logging the message of level DEBUG according to the format outlined above.
 void debug(String msg, Throwable t)
          Log a message of level DEBUG, including an exception.
 void error(String msg)
          A simple implementation which always logs messages of level ERROR according to the format outlined above.
 void error(String format, Object... argArray)
          Perform double parameter substitution before logging the message of level ERROR according to the format outlined above.
 void error(String format, Object arg)
          Perform single parameter substitution before logging the message of level ERROR according to the format outlined above.
 void error(String format, Object arg1, Object arg2)
          Perform double parameter substitution before logging the message of level ERROR according to the format outlined above.
 void error(String msg, Throwable t)
          Log a message of level ERROR, including an exception.
 String getName()
          Return the name of this Logger instance.
 void info(String msg)
          A simple implementation which logs messages of level INFO according to the format outlined above.
 void info(String format, Object... argArray)
          Perform double parameter substitution before logging the message of level INFO according to the format outlined above.
 void info(String format, Object arg)
          Perform single parameter substitution before logging the message of level INFO according to the format outlined above.
 void info(String format, Object arg1, Object arg2)
          Perform double parameter substitution before logging the message of level INFO according to the format outlined above.
 void info(String msg, Throwable t)
          Log a message of level INFO, including an exception.
 boolean isDebugEnabled()
          Are debug messages currently enabled?
 boolean isErrorEnabled()
          Are error messages currently enabled?
 boolean isInfoEnabled()
          Are info messages currently enabled?
protected  boolean isLevelEnabled(int logLevel)
          Is the given log level currently enabled?
 boolean isTraceEnabled()
          Are trace messages currently enabled?
 boolean isWarnEnabled()
          Are warn messages currently enabled?
protected  Object readResolve()
          Replace this instance with a homonymous (same name) logger returned by LoggerFactory.
 void trace(String msg)
          A simple implementation which logs messages of level TRACE according to the format outlined above.
 void trace(String format, Object... argArray)
          Perform double parameter substitution before logging the message of level TRACE according to the format outlined above.
 void trace(String format, Object param1)
          Perform single parameter substitution before logging the message of level TRACE according to the format outlined above.
 void trace(String format, Object param1, Object param2)
          Perform double parameter substitution before logging the message of level TRACE according to the format outlined above.
 void trace(String msg, Throwable t)
          Log a message of level TRACE, including an exception.
 void warn(String msg)
          A simple implementation which always logs messages of level WARN according to the format outlined above.
 void warn(String format, Object... argArray)
          Perform double parameter substitution before logging the message of level WARN according to the format outlined above.
 void warn(String format, Object arg)
          Perform single parameter substitution before logging the message of level WARN according to the format outlined above.
 void warn(String format, Object arg1, Object arg2)
          Perform double parameter substitution before logging the message of level WARN according to the format outlined above.
 void warn(String msg, Throwable t)
          Log a message of level WARN, including an exception.
 
Methods inherited from class org.slf4j.helpers.MarkerIgnoringBase
debug, debug, debug, debug, debug, error, error, error, error, error, info, info, info, info, info, isDebugEnabled, isErrorEnabled, isInfoEnabled, isTraceEnabled, isWarnEnabled, toString, trace, trace, trace, trace, trace, warn, warn, warn, warn, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.slf4j.Logger
getName
 

Field Detail

SYSTEM_PREFIX

public static final String SYSTEM_PREFIX
All system properties used by SimpleLogger start with this prefix

See Also:
Constant Field Values

DEFAULT_LOG_LEVEL_KEY

public static final String DEFAULT_LOG_LEVEL_KEY
See Also:
Constant Field Values

SHOW_DATE_TIME_KEY

public static final String SHOW_DATE_TIME_KEY
See Also:
Constant Field Values

DATE_TIME_FORMAT_KEY

public static final String DATE_TIME_FORMAT_KEY
See Also:
Constant Field Values

SHOW_THREAD_NAME_KEY

public static final String SHOW_THREAD_NAME_KEY
See Also:
Constant Field Values

SHOW_LOG_NAME_KEY

public static final String SHOW_LOG_NAME_KEY
See Also:
Constant Field Values

SHOW_SHORT_LOG_NAME_KEY

public static final String SHOW_SHORT_LOG_NAME_KEY
See Also:
Constant Field Values

LOG_FILE_KEY

public static final String LOG_FILE_KEY
See Also:
Constant Field Values

LEVEL_IN_BRACKETS_KEY

public static final String LEVEL_IN_BRACKETS_KEY
See Also:
Constant Field Values

WARN_LEVEL_STRING_KEY

public static final String WARN_LEVEL_STRING_KEY
See Also:
Constant Field Values

LOG_KEY_PREFIX

public static final String LOG_KEY_PREFIX
See Also:
Constant Field Values

currentLogLevel

protected int currentLogLevel
The current log level


name

protected String name
Method Detail

isLevelEnabled

protected boolean isLevelEnabled(int logLevel)
Is the given log level currently enabled?

Parameters:
logLevel - is this level enabled?

isTraceEnabled

public boolean isTraceEnabled()
Are trace messages currently enabled?

Returns:
True if this Logger is enabled for the TRACE level, false otherwise.

trace

public void trace(String msg)
A simple implementation which logs messages of level TRACE according to the format outlined above.

Parameters:
msg - the message string to be logged

trace

public void trace(String format,
                  Object param1)
Perform single parameter substitution before logging the message of level TRACE according to the format outlined above.

Parameters:
format - the format string
param1 - the argument

trace

public void trace(String format,
                  Object param1,
                  Object param2)
Perform double parameter substitution before logging the message of level TRACE according to the format outlined above.

Parameters:
format - the format string
param1 - the first argument
param2 - the second argument

trace

public void trace(String format,
                  Object... argArray)
Perform double parameter substitution before logging the message of level TRACE according to the format outlined above.

Parameters:
format - the format string
argArray - a list of 3 or more arguments

trace

public void trace(String msg,
                  Throwable t)
Log a message of level TRACE, including an exception.

Parameters:
msg - the message accompanying the exception
t - the exception (throwable) to log

isDebugEnabled

public boolean isDebugEnabled()
Are debug messages currently enabled?

Returns:
True if this Logger is enabled for the DEBUG level, false otherwise.

debug

public void debug(String msg)
A simple implementation which logs messages of level DEBUG according to the format outlined above.

Parameters:
msg - the message string to be logged

debug

public void debug(String format,
                  Object param1)
Perform single parameter substitution before logging the message of level DEBUG according to the format outlined above.

Parameters:
format - the format string
param1 - the argument

debug

public void debug(String format,
                  Object param1,
                  Object param2)
Perform double parameter substitution before logging the message of level DEBUG according to the format outlined above.

Parameters:
format - the format string
param1 - the first argument
param2 - the second argument

debug

public void debug(String format,
                  Object... argArray)
Perform double parameter substitution before logging the message of level DEBUG according to the format outlined above.

Parameters:
format - the format string
argArray - a list of 3 or more arguments

debug

public void debug(String msg,
                  Throwable t)
Log a message of level DEBUG, including an exception.

Parameters:
msg - the message accompanying the exception
t - the exception (throwable) to log

isInfoEnabled

public boolean isInfoEnabled()
Are info messages currently enabled?

Returns:
True if this Logger is enabled for the INFO level, false otherwise.

info

public void info(String msg)
A simple implementation which logs messages of level INFO according to the format outlined above.

Parameters:
msg - the message string to be logged

info

public void info(String format,
                 Object arg)
Perform single parameter substitution before logging the message of level INFO according to the format outlined above.

Parameters:
format - the format string
arg - the argument

info

public void info(String format,
                 Object arg1,
                 Object arg2)
Perform double parameter substitution before logging the message of level INFO according to the format outlined above.

Parameters:
format - the format string
arg1 - the first argument
arg2 - the second argument

info

public void info(String format,
                 Object... argArray)
Perform double parameter substitution before logging the message of level INFO according to the format outlined above.

Parameters:
format - the format string
argArray - a list of 3 or more arguments

info

public void info(String msg,
                 Throwable t)
Log a message of level INFO, including an exception.

Parameters:
msg - the message accompanying the exception
t - the exception (throwable) to log

isWarnEnabled

public boolean isWarnEnabled()
Are warn messages currently enabled?

Returns:
True if this Logger is enabled for the WARN level, false otherwise.

warn

public void warn(String msg)
A simple implementation which always logs messages of level WARN according to the format outlined above.

Parameters:
msg - the message string to be logged

warn

public void warn(String format,
                 Object arg)
Perform single parameter substitution before logging the message of level WARN according to the format outlined above.

Parameters:
format - the format string
arg - the argument

warn

public void warn(String format,
                 Object arg1,
                 Object arg2)
Perform double parameter substitution before logging the message of level WARN according to the format outlined above.

Parameters:
format - the format string
arg1 - the first argument
arg2 - the second argument

warn

public void warn(String format,
                 Object... argArray)
Perform double parameter substitution before logging the message of level WARN according to the format outlined above.

Parameters:
format - the format string
argArray - a list of 3 or more arguments

warn

public void warn(String msg,
                 Throwable t)
Log a message of level WARN, including an exception.

Parameters:
msg - the message accompanying the exception
t - the exception (throwable) to log

isErrorEnabled

public boolean isErrorEnabled()
Are error messages currently enabled?

Returns:
True if this Logger is enabled for the ERROR level, false otherwise.

error

public void error(String msg)
A simple implementation which always logs messages of level ERROR according to the format outlined above.

Parameters:
msg - the message string to be logged

error

public void error(String format,
                  Object arg)
Perform single parameter substitution before logging the message of level ERROR according to the format outlined above.

Parameters:
format - the format string
arg - the argument

error

public void error(String format,
                  Object arg1,
                  Object arg2)
Perform double parameter substitution before logging the message of level ERROR according to the format outlined above.

Parameters:
format - the format string
arg1 - the first argument
arg2 - the second argument

error

public void error(String format,
                  Object... argArray)
Perform double parameter substitution before logging the message of level ERROR according to the format outlined above.

Parameters:
format - the format string
argArray - a list of 3 or more arguments

error

public void error(String msg,
                  Throwable t)
Log a message of level ERROR, including an exception.

Parameters:
msg - the message accompanying the exception
t - the exception (throwable) to log

getName

public String getName()
Description copied from interface: Logger
Return the name of this Logger instance.

Specified by:
getName in interface Logger
Returns:
name of this logger instance

readResolve

protected Object readResolve()
                      throws ObjectStreamException
Replace this instance with a homonymous (same name) logger returned by LoggerFactory. Note that this method is only called during deserialization.

This approach will work well if the desired ILoggerFactory is the one references by LoggerFactory. However, if the user manages its logger hierarchy through a different (non-static) mechanism, e.g. dependency injection, then this approach would be mostly counterproductive.

Returns:
logger with same name as returned by LoggerFactory
Throws:
ObjectStreamException


Copyright © 2005-2014 QOS.ch. All Rights Reserved.