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

LOG4J_SIMPLELOG_LEVEL

Type

Level

Default value

ERROR

Default level for new logger instances.

log4j2.simplelog.<loggerName>.level

Env. variable

LOG4J_SIMPLELOG_<loggerName>_LEVEL

Type

Level

Default value

value of log4j2.simplelogLevel

Log level for a logger instance named <loggerName>.

log4j2.simplelogShowContextMap

Env. variable

LOG4J_SIMPLELOG_SHOW_CONTEXT_MAP

Type

boolean

Default value

false

If true, the full thread context map is included in each log message.

log4j2.simplelogShowlogname

Env. variable

LOG4J_SIMPLELOG_SHOWLOGNAME

Type

boolean

Default value

false

If true, the logger name is included in each log message.

log4j2.simplelogShowShortLogname

Env. variable

LOG4J_SIMPLELOG_SHOW_SHORT_LOGNAME

Type

boolean

Default value

true

If true, only the last component of a logger name is included in each log message.

log4j2.simplelogShowdatetime

Env. variable

LOG4J_SIMPLELOG_SHOWDATETIME

Type

boolean

Default value

false

If true, a timestamp is included in each log message.

log4j2.simplelogDateTimeFormat

Env. variable

LOG4J_SIMPLELOG_DATE_TIME_FORMAT

Type

SimpleDateFormat pattern

Default value

yyyy/MM/dd HH:mm:ss:SSS zzz

Date-time format to use. Ignored if log4j2.simplelogShowdatetime is false.

log4j2.simplelogLogFile

Env. variable

LOG4J_SIMPLELOG_LOG_FILE

Type

Path or predefined constant

Default value

System.err

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

LOG4J_DISABLE_THREAD_CONTEXT

Type

boolean

Default value

false

If true, the ThreadContext stack and map are disabled.

log4j2.disableThreadContextStack

Env. variable

LOG4J_DISABLE_THREAD_CONTEXT_STACK

Type

boolean

Default value

false

If true, the ThreadContext stack is disabled.

log4j2.disableThreadContextMap

Env. variable

LOG4J_DISABLE_THREAD_CONTEXT_MAP

Type

boolean

Default value

false

If true, the ThreadContext map is disabled.

log4j2.threadContextMap

Env. variable

LOG4J_THREAD_CONTEXT_MAP

Type

Class<? extends ThreadContextMap>

Default value

DefaultThreadContextMap

Fully specified class name of a custom ThreadContextMap implementation class.

log4j2.isThreadContextMapInheritable

Env. variable

LOG4J_IS_THREAD_CONTEXT_MAP_INHERITABLE

Type

boolean

Default value

false

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.