Simple Logger
Even though Log4j Core is the reference implementation of Log4j API, Log4j API itself also provides a very minimalist implementation: SimpleLogger
.
This is a convenience for environments where either a fully-fledged logging implementation is missing, or cannot be included for other reasons.
SimpleLogger
is the default Log4j API implementation if no other is available in the classpath.
Configuration
Logger
SimpleLogger
can be configured using the following system properties:
log4j2.simplelogLevel
Env. variable |
|
---|---|
Type |
|
Default value |
|
Default level for new logger instances.
log4j2.simplelog.<loggerName>.level
Env. variable |
|
---|---|
Type |
|
Default value |
value of |
Log level for a logger instance named <loggerName>
.
log4j2.simplelogShowContextMap
Env. variable |
|
---|---|
Type |
|
Default value |
|
If true
, the full thread context map is included in each log message.
log4j2.simplelogShowlogname
Env. variable |
|
---|---|
Type |
|
Default value |
|
If true
, the logger name is included in each log message.
log4j2.simplelogShowShortLogname
Env. variable |
|
---|---|
Type |
|
Default value |
|
If true
, only the last component of a logger name is included in each log message.
log4j2.simplelogShowdatetime
Env. variable |
|
---|---|
Type |
|
Default value |
|
If true
, a timestamp is included in each log message.
log4j2.simplelogDateTimeFormat
Env. variable |
|
---|---|
Type |
|
Default value |
|
Date-time format to use.
Ignored if log4j2.simplelogShowdatetime
is false
.
log4j2.simplelogLogFile
Env. variable |
|
---|---|
Type |
|
Default value |
|
Specifies the output stream used by all loggers.
Its value can be the path to a log file or one of these constants:
- System.err
-
logs to the standard error output stream,
- System.out
-
logs to the standard output stream,
Thread context
For the configuration of the thread context, Simple Logger supports a subset of the properties supported by Log4j Core:
log4j2.disableThreadContext
Env. variable |
|
---|---|
Type |
|
Default value |
|
If true
, the ThreadContext
stack and map are disabled.
log4j2.disableThreadContextStack
Env. variable |
|
---|---|
Type |
|
Default value |
|
If true
, the ThreadContext
stack is disabled.
log4j2.disableThreadContextMap
Env. variable |
|
---|---|
Type |
|
Default value |
|
If true
, the ThreadContext
map is disabled.
log4j2.threadContextMap
Env. variable |
|
---|---|
Type |
|
Default value |
Fully specified class name of a custom
ThreadContextMap
implementation class.
log4j2.isThreadContextMapInheritable
Env. variable |
|
---|---|
Type |
|
Default value |
|
If true
uses an InheritableThreadLocal
to copy the thread context map to newly created threads.
Note that, as explained in
Java’s Executors#privilegedThreadFactory()
, when you are dealing with privileged threads, thread context might not get propagated completely.