Class SimpleLogger
- All Implemented Interfaces:
Serializable
,org.slf4j.Logger
- Direct Known Subclasses:
MavenSimpleLogger
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:
org.slf4j.simpleLogger.logFile
- The output target which can be the path to a file, or the special values "System.out" and "System.err". Default is "System.err".org.slf4j.simpleLogger.cacheOutputStream
- If the output target is set to "System.out" or "System.err" (see preceding entry), by default, logs will be output to the latest value referenced bySystem.out/err
variables. By setting this parameter to true, the output stream will be cached, i.e. assigned once at initialization time and re-used independently of the current value referenced bySystem.out/err
.org.slf4j.simpleLogger.defaultLogLevel
- Default log level for all instances of SimpleLogger. Must be one of "trace", "debug", "info", "warn", "error" or "off". If not specified, defaults to "info".org.slf4j.simpleLogger.log.com.foo.bar
- Logging detail level for a SimpleLogger instance named "com.foo.bar". Right-side value must be one of "trace", "debug", "info", "warn", "error" or "off". When a SimpleLogger named "a.b.c" is initialized, its level is assigned from this property. If unspecified, the level of nearest parent logger will be used, and if none is set, then the value specified byorg.slf4j.simpleLogger.defaultLogLevel
will be used.org.slf4j.simpleLogger.showDateTime
- If you would like the current date and time to be included in output messages, then set it totrue
. Default isfalse
org.slf4j.simpleLogger.dateTimeFormat
- The date and time format to be used in the output messages. The pattern describing the date and time format is defined bySimpleDateFormat
. If the format is not specified or is invalid, the number of milliseconds since start up will be output.org.slf4j.simpleLogger.showThreadName
- If you want to output the current thread name, then set it totrue
. Defaults totrue
.- (since version 1.7.33 and 2.0.0-alpha6)
org.slf4j.simpleLogger.showThreadId
- If you would like to output the current thread id, then set totrue
. Defaults tofalse
. org.slf4j.simpleLogger.showLogName
- If you would like the Logger instance name to be included in output messages, then set it totrue
. Defaults totrue
.org.slf4j.simpleLogger.showShortLogName
- Set totrue
if you want the last component of the name to be included in output messages. Defaults tofalse
.org.slf4j.simpleLogger.levelInBrackets
- Should the level string be output in brackets? Defaults tofalse
.org.slf4j.simpleLogger.warnLevelString
- The string value output for the warn level. Defaults toWARN
.
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:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
protected int
The current log levelstatic final String
static final String
static final String
static final String
static final String
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected String
static final String
static final String
static final String
static final String
static final String
static final String
All system properties used bySimpleLogger
start with this prefixstatic final String
Fields inherited from interface org.slf4j.Logger
ROOT_LOGGER_NAME
-
Method Summary
Modifier and TypeMethodDescriptionvoid
A simple implementation which logs messages of level DEBUG according to the format outlined above.void
Perform single parameter substitution before logging the message of level DEBUG according to the format outlined above.void
Perform double parameter substitution before logging the message of level DEBUG according to the format outlined above.void
Perform double parameter substitution before logging the message of level DEBUG according to the format outlined above.void
Log a message of level DEBUG, including an exception.void
A simple implementation which always logs messages of level ERROR according to the format outlined above.void
Perform single parameter substitution before logging the message of level ERROR according to the format outlined above.void
Perform double parameter substitution before logging the message of level ERROR according to the format outlined above.void
Perform double parameter substitution before logging the message of level ERROR according to the format outlined above.void
Log a message of level ERROR, including an exception.getName()
void
A simple implementation which logs messages of level INFO according to the format outlined above.void
Perform single parameter substitution before logging the message of level INFO according to the format outlined above.void
Perform double parameter substitution before logging the message of level INFO according to the format outlined above.void
Perform double parameter substitution before logging the message of level INFO according to the format outlined above.void
Log a message of level INFO, including an exception.boolean
Aredebug
messages currently enabled?boolean
Areerror
messages currently enabled?boolean
Areinfo
messages currently enabled?protected boolean
isLevelEnabled
(int logLevel) Is the given log level currently enabled?boolean
Aretrace
messages currently enabled?boolean
Arewarn
messages currently enabled?void
log
(org.slf4j.event.LoggingEvent event) protected Object
protected String
renderLevel
(int level) void
A simple implementation which logs messages of level TRACE according to the format outlined above.void
Perform single parameter substitution before logging the message of level TRACE according to the format outlined above.void
Perform double parameter substitution before logging the message of level TRACE according to the format outlined above.void
Perform double parameter substitution before logging the message of level TRACE according to the format outlined above.void
Log a message of level TRACE, including an exception.void
A simple implementation which always logs messages of level WARN according to the format outlined above.void
Perform single parameter substitution before logging the message of level WARN according to the format outlined above.void
Perform double parameter substitution before logging the message of level WARN according to the format outlined above.void
Perform double parameter substitution before logging the message of level WARN according to the format outlined above.void
Log a message of level WARN, including an exception.protected void
writeThrowable
(Throwable t, PrintStream targetStream) 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 Details
-
LOG_LEVEL_TRACE
protected static final int LOG_LEVEL_TRACE- See Also:
-
LOG_LEVEL_DEBUG
protected static final int LOG_LEVEL_DEBUG- See Also:
-
LOG_LEVEL_INFO
protected static final int LOG_LEVEL_INFO- See Also:
-
LOG_LEVEL_WARN
protected static final int LOG_LEVEL_WARN- See Also:
-
LOG_LEVEL_ERROR
protected static final int LOG_LEVEL_ERROR- See Also:
-
LOG_LEVEL_OFF
protected static final int LOG_LEVEL_OFF- See Also:
-
currentLogLevel
protected int currentLogLevelThe current log level -
SYSTEM_PREFIX
All system properties used bySimpleLogger
start with this prefix- See Also:
-
LOG_KEY_PREFIX
- See Also:
-
CACHE_OUTPUT_STREAM_STRING_KEY
- See Also:
-
WARN_LEVEL_STRING_KEY
- See Also:
-
LEVEL_IN_BRACKETS_KEY
- See Also:
-
LOG_FILE_KEY
- See Also:
-
SHOW_SHORT_LOG_NAME_KEY
- See Also:
-
SHOW_LOG_NAME_KEY
- See Also:
-
SHOW_THREAD_NAME_KEY
- See Also:
-
SHOW_THREAD_ID_KEY
- See Also:
-
DATE_TIME_FORMAT_KEY
- See Also:
-
SHOW_DATE_TIME_KEY
- See Also:
-
DEFAULT_LOG_LEVEL_KEY
- See Also:
-
name
-
-
Method Details
-
renderLevel
-
writeThrowable
-
isLevelEnabled
protected boolean isLevelEnabled(int logLevel) Is the given log level currently enabled?- Parameters:
logLevel
- is this level enabled?
-
isTraceEnabled
public boolean isTraceEnabled()Aretrace
messages currently enabled? -
trace
A simple implementation which logs messages of level TRACE according to the format outlined above. -
trace
Perform single parameter substitution before logging the message of level TRACE according to the format outlined above. -
trace
Perform double parameter substitution before logging the message of level TRACE according to the format outlined above. -
trace
Perform double parameter substitution before logging the message of level TRACE according to the format outlined above. -
trace
Log a message of level TRACE, including an exception. -
isDebugEnabled
public boolean isDebugEnabled()Aredebug
messages currently enabled? -
debug
A simple implementation which logs messages of level DEBUG according to the format outlined above. -
debug
Perform single parameter substitution before logging the message of level DEBUG according to the format outlined above. -
debug
Perform double parameter substitution before logging the message of level DEBUG according to the format outlined above. -
debug
Perform double parameter substitution before logging the message of level DEBUG according to the format outlined above. -
debug
Log a message of level DEBUG, including an exception. -
isInfoEnabled
public boolean isInfoEnabled()Areinfo
messages currently enabled? -
info
A simple implementation which logs messages of level INFO according to the format outlined above. -
info
Perform single parameter substitution before logging the message of level INFO according to the format outlined above. -
info
Perform double parameter substitution before logging the message of level INFO according to the format outlined above. -
info
Perform double parameter substitution before logging the message of level INFO according to the format outlined above. -
info
Log a message of level INFO, including an exception. -
isWarnEnabled
public boolean isWarnEnabled()Arewarn
messages currently enabled? -
warn
A simple implementation which always logs messages of level WARN according to the format outlined above. -
warn
Perform single parameter substitution before logging the message of level WARN according to the format outlined above. -
warn
Perform double parameter substitution before logging the message of level WARN according to the format outlined above. -
warn
Perform double parameter substitution before logging the message of level WARN according to the format outlined above. -
warn
Log a message of level WARN, including an exception. -
isErrorEnabled
public boolean isErrorEnabled()Areerror
messages currently enabled? -
error
A simple implementation which always logs messages of level ERROR according to the format outlined above. -
error
Perform single parameter substitution before logging the message of level ERROR according to the format outlined above. -
error
Perform double parameter substitution before logging the message of level ERROR according to the format outlined above. -
error
Perform double parameter substitution before logging the message of level ERROR according to the format outlined above. -
error
Log a message of level ERROR, including an exception. -
log
public void log(org.slf4j.event.LoggingEvent event) -
getName
- Specified by:
getName
in interfaceorg.slf4j.Logger
-
readResolve
- Throws:
ObjectStreamException
-