Configuration properties

Log4j contains a simple configuration properties sub-system that aggregates data from multiple property sources, such as Java System Properties and Environment Variables. See Property sources for a complete list of supported sources

Global configuration properties are used by Log4j in the following situations:

  • to finely tune global Log4j API and Log4j Core services that are independent of the configuration file,

  • to change the default values of attributes used in a configuration file.

Since Log4j 2.10 all the property names follow a common naming scheme:

log4j2.camelCasePropertyName

except the environment variables, which follow the:

LOG4J_CAMEL_CASE_PROPERTY_NAME

convention.

If a log4j2.system.properties file is available on the classpath its contents are sourced into Java system properties at Log4j startup.

To provide backward compatibility with versions older than 2.10.0 a certain number of additional property names are also supported using a fuzzy matching algorithm.

In case of problems with the properties sub-system, make sure that your application does not use property names with the following case-insensitive prefixes:

  • asyncLogger,

  • disableThreadContext,

  • isThreadContext,

  • org.apache.logging.log4j

and that all the properties names that start with log4j use the normalized form provided by the tables below.

Meta configuration properties

In order to rapidly optimize Log4j Core for a particular usage, you can use the following properties:

log4j2.isWebapp

Env. variable

LOG4J_IS_WEBAPP

Type

boolean

Default value

true if the Servlet class on classpath,

false otherwise

Setting this property to true switches Log4j Core into "Web application mode" ("Web-app mode").

In this mode Log4j is optimized to work in a Servlet container.

This mode is incompatible with log4j2.enableThreadlocals.

log4j2.enableThreadlocals

Env. variable

LOG4J_ENABLE_THREADLOCALS

Type

boolean

Default value

false if Web-app mode is enabled,

true otherwise

Setting this property to true switches Log4j Core into "garbage-free mode" ("GC-free mode").

In this mode Log4j uses ThreadLocals for object pooling to prevent object allocations.

ThreadLocal fields holding non-JDK classes can cause memory leaks in web applications when the application server’s thread pool continues to reference these fields after the web application is undeployed. Hence, to avoid causing memory leaks, log4j2.enableThreadlocals by default reflects the opposite of log4j2.isWebapp.

Log4j API properties

The services included in the log4j-api module can be configured exclusively through configuration properties.

LoaderUtil

The LoaderUtil class is used to load classes specified by the user using a fully qualified class name. Therefore, its configuration influences all other services.

It has only one configuration property:

log4j2.ignoreTcl

Env. variable

LOG4J_IGNORE_TCL

Type

boolean

Default value

false

If true, classes are only loaded using the same classloader that loaded Log4j.

Otherwise, an attempt is made to load classes with the current thread’s context class loader before falling back to the default class loader.

Provider

The runtime classpath of an application should contain only a single implementation of the Log4j API. In the particular case, when multiple implementations are present, you can select a specific implementation using these properties:

log4j2.provider

Env. variable

LOG4J_PROVIDER

Type

Class<? extends Provider>

Default value

automatically detected

Since

2.24.0

Fully qualified class name of the Log4j API Provider to use.

By default, Log4j uses ServiceLoader to select the provider to use. In case multiple providers are found on the classpath the provider with the highest priority is selected and a WARN message is logger by Status Logger.

log4j2.loggerContextFactory

Env. variable

LOG4J_LOGGER_CONTEXT_FACTORY

Type

Class<? extends LoggerContextFactory>

Default value

automatically detected

Since version 2.24.0 this property is deprecated, use log4j2.provider instead.

Fully qualified class name of the LoggerContextFactory to use to create Loggers.

By default, Log4j uses Provider.getLoggerContextFactory() to get a logger context factory. If log4j2.provider is set, this property is ignored.

Log4j Core properties

While the only required configuration of the log4j-core library is provided by the configuration file, the library offers many configuration properties that can be used to finely tune the way it works.

Async components

The behavior of all three async components (AsyncLogger, AsyncLoggerConfig and AsyncAppender) can be tuned using these properties:

log4j2.formatMsgAsync

Env. variable

LOG4J_FORMAT_MSG_ASYNC

Type

boolean

Default value

false

If false, Log4j will make sure the message is formatted in the caller thread, otherwise the formatting will occur on the asynchronous thread.

Remark: messages annotated with AsynchronouslyFormattable will be formatted on the async thread regardless of this setting.

log4j2.asyncQueueFullPolicy

Env. variable

LOG4J_ASYNC_QUEUE_FULL_POLICY

Type

Class<? extends AsyncQueueFullPolicy> or predefined constant

Default value

Default

Determines the AsyncQueueFullPolicy to use when the underlying async component cannot keep up with the logging rate and the queue is filling up.

Its value should be the fully qualified class name of an AsyncQueueFullPolicy implementation or one of these predefined constants:

Default

blocks the calling thread until the event can be added to the queue.

Discard

when the queue is full, it drops the events whose level is equal or less than the threshold level (see log4j2.discardThreshold).

log4j2.discardThreshold

Env. variable

LOG4J_DISCARD_THRESHOLD

Type

Level

Default value

INFO

Determines the threshold level used by a Discard queue full policy. Log events whose level is not more severe than the threshold level will be discarded during a queue full event. See also log4j2.asyncQueueFullPolicy.

Full asynchronous logger

The AsyncLogger component supports the following additional properties:

log4j2.asyncLoggerExceptionHandler

Env. variable

LOG4J_ASYNC_LOGGER_EXCEPTION_HANDLER

Type

Class<? extends ExceptionHandler<? super RingBufferLogEvent>>

Default value

AsyncLoggerDefaultExceptionHandler

Fully qualified name of a class that implements the ExceptionHandler interface, which will be notified when an exception occurs while logging messages. The class needs to have a public zero-argument constructor.

The default exception handler will print a message and stack trace to the standard error output stream.

log4j2.asyncLoggerRingBufferSize

Env. variable

LOG4J_ASYNC_LOGGER_RING_BUFFER_SIZE

Type

int

Default value

256 × 1024

(GC-free mode: 4 × 1024)

Size (number of slots) in the RingBuffer used by the asynchronous logging subsystem. Make this value large enough to deal with bursts of activity. The minimum size is 128. The RingBuffer will be pre-allocated at first use and will never grow or shrink during the life of the system.

When the application is logging faster than the underlying appender can keep up with for a long enough time to fill up the queue, the behaviour is determined by the AsyncQueueFullPolicy.

log4j2.asyncLoggerWaitStrategy

Env. variable

LOG4J_ASYNC_LOGGER_WAIT_STRATEGY

Type

predefined constant

Default value

Timeout

Specifies the WaitStrategy used by the LMAX Disruptor.

The value needs to be one of the predefined constants:

Block

a strategy that uses a lock and condition variable for the I/O thread waiting for log events. Block can be used when throughput and low-latency are not as important as CPU resource. Recommended for resource constrained/virtualized environments. This wait strategy is not garbage free.

Timeout

a variation of the Block strategy that will periodically wake up from the lock condition await() call. This ensures that if a notification is missed somehow the consumer thread is not stuck but will recover with a small latency delay, see log4j2.asyncLoggerTimeout. This wait strategy is garbage free.

Sleep

a strategy that initially spins, then uses a Thread.yield(), and eventually parks for the minimum number of nanos the OS and JVM will allow while the I/O thread is waiting for log events (see log4j2.asyncLoggerRetries and log4j2.asyncLoggerSleepTimeNs). Sleep is a good compromise between performance and CPU resource. This strategy has very low impact on the application thread, in exchange for some additional latency for actually getting the message logged. This wait strategy is garbage free.

Yield

is a strategy that will use 100% CPU, but will give up the CPU if other threads require CPU resources. This wait strategy is garbage free.

log4j2.asyncLoggerTimeout

Env. variable

LOG4J_ASYNC_LOGGER_TIMEOUT

Type

int

Default value

10

Timeout in milliseconds of Timeout wait strategy (see log4j2.asyncLoggerWaitStrategy).

log4j2.asyncLoggerSleepTimeNs

Env. variable

LOG4J_ASYNC_LOGGER_SLEEP_TIME_NS

Type

long

Default value

100

Sleep time in nanoseconds of Sleep wait strategy (see log4j2.asyncLoggerWaitStrategy).

log4j2.asyncLoggerRetries

Env. variable

LOG4J_ASYNC_LOGGER_RETRIES

Type

int

Default value

200

Total number of spin cycles and Thread.yield() cycles of Sleep (see log4j2.asyncLoggerWaitStrategy).

log4j2.asyncLoggerSynchronizeEnqueueWhenQueueFull

Env. variable

LOG4J_ASYNC_LOGGER_SYNCHRONIZE_ENQUEUE_WHEN_QUEUE_FULL

Type

boolean

Default value

true

Synchronizes access to the Disruptor ring buffer for blocking enqueue operations when the queue is full. Users encountered excessive CPU utilization with Disruptor v3.4.2 when the application was logging more than the underlying appender could keep up with and the ring buffer became full, especially when the number of application threads vastly outnumbered the number of cores. CPU utilization is significantly reduced by restricting access to the enqueue operation. Setting this value to false may lead to very high CPU utilization when the async logging queue is full.

log4j2.asyncLoggerThreadNameStrategy

Env. variable

LOG4J_ASYNC_LOGGER_HREAD_NAME_STRATEGY

Type

ThreadNameCachingStrategy (enumeration)

Default value

UNCACHED for JRE 8u102 or later,

CACHED otherwise

Specifies the ThreadNameCachingStrategy to use to cache the result of Thread#getName().

This setting allows to cache the result of Thread.getName() calls and has two values:

CACHED

stores the name of the current thread in a ThreadLocal field,

UNCACHED

disables caching.

Since JRE 8u102 the Thread.getName() method does not allocate a new object.

Mixed asynchronous logger

The AsyncLoggerConfig component supports the following additional properties:

log4j2.asyncLoggerConfigExceptionHandler

Env. variable

LOG4J_ASYNC_LOGGER_CONFIG_EXCEPTION_HANDLER

Type

Class<? extends ExceptionHandler<? super Log4jEventWrapper>>

Default value

AsyncLoggerConfigDefaultExceptionHandler

Fully qualified name of a class that implements the ExceptionHandler interface, which will be notified when an exception occurs while logging messages. The class needs to have a public zero-argument constructor.

The default exception handler will print a message and stack trace to the standard error output stream.

log4j2.asyncLoggerRingConfigBufferSize

Env. variable

LOG4J_ASYNC_LOGGER_CONFIG_RING_BUFFER_SIZE

Type

int

Default value

256 × 1024

(GC-free mode: 4 × 1024)

Size (number of slots) in the RingBuffer used by the asynchronous logging subsystem. Make this value large enough to deal with bursts of activity. The minimum size is 128. The RingBuffer will be pre-allocated at first use and will never grow or shrink during the life of the system.

When the application is logging faster than the underlying appender can keep up with for a long enough time to fill up the queue, the behaviour is determined by the AsyncQueueFullPolicy.

log4j2.asyncLoggerConfigWaitStrategy

Env. variable

LOG4J_ASYNC_LOGGER_CONFIG_WAIT_STRATEGY

Type

predefined constant

Default value

Timeout

Specifies the WaitStrategy used by the LMAX Disruptor.

The value needs to be one of the predefined constants:

Block

a strategy that uses a lock and condition variable for the I/O thread waiting for log events. Block can be used when throughput and low-latency are not as important as CPU resource. Recommended for resource constrained/virtualised environments.

Timeout

a variation of the Block strategy that will periodically wake up from the lock condition await() call. This ensures that if a notification is missed somehow the consumer thread is not stuck but will recover with a small latency delay (see log4j2.asyncLoggerTimeout)

Sleep

a strategy that initially spins, then uses a Thread.yield(), and eventually parks for the minimum number of nanos the OS and JVM will allow while the I/O thread is waiting for log events (see log4j2.asyncLoggerRetries and log4j2.asyncLoggerSleepTimeNs). Sleep is a good compromise between performance and CPU resource. This strategy has very low impact on the application thread, in exchange for some additional latency for actually getting the message logged.

Yield

is a strategy that will use 100% CPU, but will give up the CPU if other threads require CPU resources.

See also Custom WaitStrategy for an alternative way to configure the wait strategy.

log4j2.asyncLoggerConfigTimeout

Env. variable

LOG4J_ASYNC_LOGGER_CONFIG_TIMEOUT

Type

int

Default value

10

Timeout in milliseconds of Timeout wait strategy (see log4j2.asyncLoggerConfigWaitStrategy).

log4j2.asyncLoggerConfigSleepTimeNs

Env. variable

LOG4J_ASYNC_LOGGER_CONFIG_SLEEP_TIME_NS

Type

long

Default value

100

Sleep time in nanoseconds of Sleep wait strategy (see log4j2.asyncLoggerConfigWaitStrategy)).

log4j2.asyncLoggerConfigRetries

Env. variable

LOG4J_ASYNC_LOGGER_CONFIG_RETRIES

Type

int

Default value

200

Total number of spin cycles and Thread.yield() cycles of Sleep (see log4j2.asyncLoggerConfigWaitStrategy)).

log4j2.asyncLoggerConfigSynchronizeEnqueueWhenQueueFull

Env. variable

LOG4J_ASYNC_LOGGER_CONFIG_SYNCHRONIZE_ENQUEUE_WHEN_QUEUE_FULL

Type

boolean

Default value

true

Synchronizes access to the Disruptor ring buffer for blocking enqueue operations when the queue is full. Users encountered excessive CPU utilization with Disruptor v3.4.2 when the application was logging more than the underlying appender could keep up with and the ring buffer became full, especially when the number of application threads vastly outnumbered the number of cores. CPU utilization is significantly reduced by restricting access to the enqueue operation. Setting this value to false may lead to very high CPU utilization when the async logging queue is full.

Context selector

The ContextSelector component specifies the strategy used by Log4j to create new logger contexts. The choice of ContextSelector determines in particular:

  • how loggers are divided among logger contexts. See Log Separation for details.

  • the Logger implementation used by Log4j Core. See Async Logging as an example of this usage.

log4j2.contextSelector

Env. variable

LOG4J_CONTEXT_SELECTOR

Type

Class<? extends ContextSelector>

Default value

ClassLoaderContextSelector

Specifies the fully qualified class name of the ContextSelector implementation to use.

The implementations available by default are:

org.apache.logging.log4j.core.selector.BasicContextSelector

Creates a single logger context and synchronous loggers

org.apache.logging.log4j.core.async.BasicAsyncLoggerContextSelector

Creates a single logger context and asynchronous loggers

org.apache.logging.log4j.core.selector.ClassLoaderContextSelector

Creates a separate logger context per classloader and synchronous loggers

org.apache.logging.log4j.core.async.AsyncLoggerContextSelector

Creates a separate logger context per classloader and asynchronous loggers

org.apache.logging.log4j.core.osgi.BundleContextSelector

Creates a separate logger context per OSGi bundle and synchronous loggers

org.apache.logging.log4j.core.selector.JndiContextSelector

Creates loggers contexts based on a JNDI lookup and synchronous loggers See Web application for details.

Configuration factory

Since configuration factories are used to parse the configuration file, they can only be configured through global configuration properties.

Log4j Core supports both local and remote configuration files. If a remote configuration file is used, its transport must be secured. See Transport security for details.

log4j2.configurationFactory

Env. variable

LOG4J_CONFIGURATION_FACTORY

Type

Class<? extends ConfigurationFactory>

Default value

null

Specifies the fully qualified class name of the preferred ConfigurationFactory to use.

Log4j will attempt to use the provided configuration factory before any other factory implementation.

log4j2.configurationFile

Env. variable

LOG4J_CONFIGURATION_FILE

Type

Comma-separated list of Paths or URIs

Default value

automatically detected

Specifies a comma-separated list of URIs or file paths to Log4j 2 configuration files.

If a relative URL is provided, it is interpreted as:

  • path to a file, if the file exists,

  • a classpath resource otherwise.

Usage of absolute URLs is restricted by the Transport Security configuration options.

log4j2.level

Env. variable

LOG4J_LEVEL

Type

Level

Default value

ERROR

Specifies the level of the root logger if:

  • the default configuration is used,

  • or the configuration file does not specify a level for the root logger.

log4j2.mergeStrategy

Env. variable

LOG4J_MERGE_STRATEGY

Type

Class<? extends MergeStrategy>

Default value

DefaultMergeStrategy

Specifies the fully qualified class name of the MergeStrategy implementation used to merge multiple configuration files into one.

Garbage Collection

log4j2.enableDirectEncoders

Env. variable

LOG4J_ENABLE_DIRECT_ENCODERS

Type

boolean

Default value

true

If true, garbage-aware layouts will directly encode log events into ByteBuffers provided by appenders.

This prevents allocating temporary String and char[] instances.

log4j2.encoderByteBufferSize

Env. variable

LOG4J_ENCODER_BYTE_BUFFER_SIZE

Type

int

Default value

8192

The size in bytes of the ByteBuffers stored in ThreadLocal fields by layouts and StringBuilderEncoders.

This setting is only used if log4j2.enableDirectEncoders is set to true.

log4j2.encoderCharBufferSize

Env. variable

LOG4J_ENCODER_CHAR_BUFFER_SIZE

Type

int

Default value

4096

The size in chars of the ByteBuffers stored in ThreadLocal fields StringBuilderEncoders.

This setting is only used if log4j2.enableDirectEncoders is set to true.

log4j2.initialReusableMsgSize

Env. variable

LOG4J_INITIAL_REUSABLE_MSG_SIZE

Type

int

Default value

128

In GC-free mode, this property determines the initial size of the reusable StringBuilders used by ReusableMessages for formatting purposes.

log4j2.maxReusableMsgSize

Env. variable

LOG4J_MAX_REUSABLE_MSG_SIZE

Type

int

Default value

518

In GC-free mode, this property determines the maximum size of the reusable StringBuilders used by ReusableMessages for formatting purposes.

The default value allows is equal to 2 × (2 × log4j.initialReusableMsgSize + 2) + 2 and allows the StringBuilder to be resized twice by the current JVM resize algorithm.

log4j2.layoutStringBuilderMaxSize

Env. variable

LOG4J_LAYOUT_STRING_BUILDER_MAX_SIZE

Type

int

Default value

2048

This property determines the maximum size of the reusable StringBuilders used to format LogEvents.

log4j2.unboxRingbufferSize

Env. variable

LOG4J_UNBOX_RINGBUFFER_SIZE

Type

int

Default value

32

The Unbox utility class can be used by users to format primitive values without incurring in the boxing allocation cost.

This property specifies the maximum number of primitive arguments to a log message that will be cached and usually does not need to be changed.

JANSI

If the JANSI library is on the runtime classpath of the application, the following property can be used to control its usage:

log4j2.skipJansi

Env. variable

LOG4J_SKIP_JANSI

Type

boolean

Default value

true

If the following conditions are satisfied:

  • Log4j runs on Windows,

  • this property is set to false,

Log4j will use the JANSI library to color the output of the console appender.

JMX

log4j2.disableJmx

Env. variable

LOG4J_DISABLE_JMX

Type

boolean

Default value

true

If false, Log4j configuration objects like LoggerContexts, Appenders, Loggers, etc. will be instrumented with MBeans and can be remotely monitored and managed.

log4j2.jmxNotifyAsync

Env. variable

LOG4J_JMX_NOTIFY_ASYNC

Type

int

Default value

true

(Web-app mode: false)

If true, Log4j’s JMX notifications are sent from a separate background thread, otherwise they are sent from the caller thread.

JNDI

Due to the inherent security problems of JNDI, its usage in Log4j is restricted to the java: protocol.

Moreover, each JNDI usage must be explicitly enabled by the user through the following configuration properties.

log4j2.enableJndiContextSelector

Env. variable

LOG4J_ENABLE_JNDI_CONTEXT_SELECTOR

Type

boolean

Default value

false

When true the JndiContextSelector is enabled for the java: protocol. See Web application for more details.

log4j2.enableJndiJdbc

Env. variable

LOG4J_ENABLE_JNDI_JDBC

Type

boolean

Default value

false

When true, a Log4j JDBC Appender can use JNDI to retrieve a DataSource using the java: protocol.

log4j2.enableJndiJms

Env. variable

LOG4J_ENABLE_JNDI_JMS

Type

boolean

Default value

false

When true, a Log4j JMS Appender can use JNDI to retrieve the necessary components using the java: protocol.

log4j2.enableJndiLookup

Env. variable

LOG4J_ENABLE_JNDI_LOOKUP

Type

boolean

Default value

false

When true, the Log4j JNDI Lookup can use the java: protocol.

Thread context

The behavior of the ThreadContext class can be fine-tuned using the following properties.

These configuration properties are only used by the Log4j Core and Simple Logger implementations of Log4j API.

The log4j-to-slf4j logging bridge delegates ThreadContext calls to the SLF4J MDC class.

The log4j-to-jul logging bridge ignores all ThreadContext method calls.

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> or predefined constant

Default value

WebApp

Fully specified class name of a custom ThreadContextMap implementation class or (since version 2.24.0) one of the predefined constants:

NoOp

to disable the thread context,

WebApp

a web application-safe implementation, that only binds JRE classes to ThreadLocal to prevent memory leaks,

GarbageFree

a garbage-free implementation.

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.

log4j2.garbagefreeThreadContextMap

Env. variable

LOG4J_GARBAGEFREE_THREAD_CONTEXT_MAP

Default value

false

If set to true selects a garbage-free thread context map implementation.

Transport security

Since configuration files can be used to load arbitrary classes into a Log4j Core Configuration, users need to ensure that all the configuration elements come from trusted sources (cf. Thread model for more information).

In order to protect the user Log4j disables the http URI scheme by default and provides several configuration options to ensure secure transport of configuration files:

log4j2.configurationAllowedProtocols

Env. variable

LOG4J_CONFIGURATION_ALLOWED_PROTOCOLS

Type

Comma-separated list of URL protocols

Default value

file, https, jar

A comma separated list of URL protocols that may be used to load any kind of configuration source.

To completely prevent accessing the configuration via the Java URL class specify a value of _none.

NOTE

Since Log4j does not use URL to access file: resources, this protocol can not be effectively disabled.

log4j2.configurationAuthorizationProvider

Env. variable

LOG4J_CONFIGURATION_AUTHORIZATION_PROVIDER

Type

Class<? extends AuthorizationProvider>

Default value

BasicAuthorizationProvider

The fully qualified class name of the AuthorizationProvider implementation to use with http and https URL protocols.

log4j2.configurationAuthorizationEncoding

Env. variable

LOG4J_CONFIGURATION_AUTHORIZATION_ENCODING

Type

Charset

Default value

UTF-8

The encoding used in Basic Authentication (cf. RFC 7617).

log4j2.configurationPassword

Env. variable

LOG4J_CONFIGURATION_PASSWORD

Type

String

Default value

null

The password to use in HTTP Basic authentication.

If used in conjunction with log4j2.configurationPasswordDecryptor the contents of this variable are interpreted by the decryptor.

log4j2.configurationPasswordDecryptor

Env. variable

LOG4J_CONFIGURATION_PASSWORD_DECRYPTOR

Type

Class<? extends PasswordDecryptor>

Default value

null

Fully qualified class name of an implementation of PasswordDecryptor to use for the value of the log4j2.configurationPassword property.

If null, the literal value of the password is used.

log4j2.configurationUsername

Env. variable

LOG4J_CONFIGURATION_USERNAME

Type

String

Default value

null

The username used in HTTP Basic authentication.

log4j2.trustStoreLocation

Env. variable

LOG4J_TRUST_STORE_LOCATION

Type

Path or URI

Default value

see Default Java trust store

The location of the trust store.

log4j2.trustStorePassword

Env. variable

LOG4J_TRUST_STORE_PASSWORD

Type

String

Default value

null

The password for the trust store.

log4j2.trustStorePasswordFile

Env. variable

LOG4J_TRUST_STORE_PASSWORD_FILE

Type

Path

Default value

null

The name of a file that contains the password for the trust store.

log4j2.trustStorePasswordEnvironmentVariable

Env. variable

LOG4J_TRUST_STORE_PASSWORD_ENVIRONMENT_VARIABLE

Type

String

Default value

null

The name of the environment variable that contains password for the trust store.

log4j2.trustStoreType

Env. variable

LOG4J_TRUST_STORE_TYPE

Type

KeyStore type

Default value

Default Java KeyStore type

The type of trust store.

log4j2.trustStoreKeyManagerFactoryAlgorithm

Env. variable

LOG4J_TRUST_STORE_KEY_MANAGER_FACTORY_ALGORITHM

Type

KeyManagerFactory

Default value

Default Java KeyManagerFactory algorithm

Name of the KeyManagerFactory implementation to use for the trust store.

log4j2.sslVerifyHostName

Env. variable

LOG4J_SSL_VERIFY_HOST_NAME

Type

boolean

Default value

false

If true enables verification of the name of the TLS server.

log4j2.keyStoreLocation

Env. variable

LOG4J_KEY_STORE_LOCATION

Type

Path or URI

Default value

see Default Java key store

The location of the private key store.

log4j2.keyStorePassword

Env. variable

LOG4J_KEY_STORE_PASSWORD

Type

String

Default value

null

The password for the private key store.

log4j2.keyStorePasswordFile

Env. variable

LOG4J_KEY_STORE_PASSWORD_FILE

Type

Path

Default value

null

The name of a file that contains the password for the private key store.

log4j2.keyStorePasswordEnvironmentVariable

Env. variable

LOG4J_KEY_STORE_PASSWORD_ENVIRONMENT_VARIABLE

Type

String

Default value

null

The name of the environment variable that contains the password for the private key store.

log4j2.keyStoreType

Env. variable

LOG4J_KEY_STORE_TYPE

Type

KeyStore

Default value

Default Java KeyStore type

The type of private key store. See KeyStore.

log4j2.keyStoreKeyManagerFactoryAlgorithm

Env. variable

LOG4J_KEY_STORE_KEY_MANAGER_FACTORY_ALGORITHM

Type

KeyManagerFactory

Default value

Default Java KeyManagerFactory algorithm

Name of the KeyManagerFactory implementation to use for the private key store. See KeyManagerFactory.

Miscellaneous properties

log4j2.clock

Env. variable

LOG4J_CLOCK

Type

Class<? extends Clock> or predefined constant

Default value

SystemClock

Specifies the Clock implementation used to timestamp log events.

This must be the fully qualified class name of the implementation or one of these predefined constants:

SystemClock

uses the best available system clock as time source. See Clock#systemDefaultZone() for details.

SystemMillisClock

same as SystemClock, but truncates the result to a millisecond.

CachedClock

uses a separate thread to update the timestamp value. See CachedClock for details.

CoarseCachedClock

alternative implementation of CachedClock with a slightly lower precision. See CoarseCachedClock for details.

log4j2.contextData

Env. variable

LOG4J_CONTEXT_DATA

Type

Class<? extends StringMap>

Default value

SortedArrayStringMap

Fully qualified class name of a StringMap implementation to use to store context data in log events. The implementation must have:

  • a no-arg contructor,

  • a constructor accepting a single int parameter that specifies the capacity of the string map.

log4j2.contextDataInjector

Env. variable

LOG4J_CONTEXT_DATA_INJECTOR

Type

Class<? extends ContextDataInjector>

Default value

depends on the ThreadContextMap implementation

Fully qualified class name of a ContextDataInjector implementation.

The default implementation uses all implementations of ContextDataProvider registered with ServiceLoader.

log4j2.logEventFactory

Env. variable

LOG4J_LOG_EVENT_FACTORY

Type

Class<? extends LogEventFactory>

Default value

DefaultLogEventFactory

(GC-free mode: ReusableLogEventFactory)

Specifies the LogEventFactory implementation to use to create log events.

log4j2.reliabilityStrategy

Env. variable

LOG4J_RELIABILITY_STRATEGY

Type

Class<? extends ReliabilityStrategy> or predefined constant

Default value

AwaitCompletion

Specifies the ReliabilityStrategy to adopt in order to prevent loss of log events during a reconfiguration.

The value must be the fully qualified class name of a ReliabilityStrategy implementation or one of these predefined constants:

AwaitCompletion

Counts the number of threads that have started to log an event but have not completed yet and waits for these threads to finish before stopping the appenders.

AwaitUnconditionally

Waits for a configured amount of time before stopping the appenders. See log4j2.waitMillisBeforeStopOldConfig.

Locking

Uses read/write locks to prevent appenders from stopping while some threads are still logging events.

log4j2.waitMillisBeforeStopOldConfig

Env. variable

LOG4J_WAIT_MILLIS_BEFORE_STOP_OLD_CONFIG

Type

long

Default value

5000

Number of milliseconds to wait before stopping the old configuration if the AwaitUnconditionally reliability strategy is used. See log4j2.reliabilityStrategy.

log4j2.shutdownHookEnabled

Env. variable

LOG4J_SHUTDOWN_HOOK_ENABLED

Type

boolean

Default value

true

(Web-app mode: false)

If true a shutdown hook will be installed to stop all logger contexts when the system stops.

log4j2.shutdownCallbackRegistry

Env. variable

LOG4J_SHUTDOWN_CALLBACK_REGISTRY

Type

Class<? extends ShutdownCallbackRegistry>

Default value

DefaultShutdownCallbackRegistry

The fully qualified class name of a ShutdownCallbackRegistry implementation. Integrators can use this to customize the shutdown order of the JVM.

The default implementation executes all shutdown actions in a separate Thread registered through Runtime#addShutdownHook().

log4j2.uuidSequence

Env. variable

LOG4J_UUID_SEQUENCE

Type

long

Default value

0

Provides a long see to the UUID generator used by the %uuid pattern converter.

Can be used to assure uniqueness of UUIDs generated by multiple JVMs on the same machine.

log4j2.messageFactory

Env. variable

LOG4J_MESSAGE_FACTORY

Type

Class<? extends MessageFactory>

Default value

ParameterizeMessageFactory

(GC-free mode: ReusableMessageFactory)

Fully qualified class name of a MessageFactory implementation that will be used by loggers if no explicit factory was specified.

log4j2.flowMessageFactory

Env. variable

LOG4J_FLOW_MESSAGE_FACTORY

Type

Class<? extends FlowMessageFactory>

Default value

DefaultFlowMessageFactory

Fully qualified class name of a FlowMessageFactory implementation to be used by all loggers.

log4j2.loggerContextStacktraceOnStart

Env. variable

LOG4J_LOGGER_CONTEXT_STACKTRACE_ON_START

Type

boolean

Default value

false

Prints a stacktrace to the Status Logger at DEBUG level when the LoggerContext is started.

For debug purposes only.

log4j2.scriptEnableLanguages

Env. variable

LOG4J_SCRIPT_ENABLE_LANGUAGES

Type

Comma-separated list of ScriptEngine names

Default value

empty

The list of script languages that are allowed to execute.

The names specified must correspond to those returned by ScriptEngineFactory.getNames().

Other components

JUL-to-Log4j API bridge properties

The JUL-to-Log4j API bridge provides the following configuration properties:

log4j2.julLevelConverter

Env. variable

LOG4J_JUL_LEVEL_CONVERTER

Type

Class<? extends LevelConverter>

Default value

org.apache.logging.log4j.jul.DefaultLevelConverter

Fully qualified name of an alternative org.apache.logging.log4j.jul.LevelConverter implementation.

Default level conversions
Java Level Log4j Level

OFF

OFF

SEVERE

ERROR

WARNING

WARN

INFO

INFO

CONFIG

custom CONFIG level with a numeric value of 450

FINE

DEBUG

FINER

TRACE

FINEST

custom FINEST level with a numeric value of 700

ALL

ALL

log4j2.julLoggerAdapter

Env. variable

LOG4J_JUL_LOGGER_ADAPTER

Type

Class<? extends AbstractLoggerAdapter>

Default value

org.apache.logging.log4j.jul.ApiLoggerAdapter

Fully qualified class name of the org.apache.logging.log4j.jul.AbstractLoggerAdapter implementation to use.

This property allows users to choose between two implementations of the logging bridge:

org.apache.logging.log4j.jul.CoreLoggerAdapter

It allows users to modify the Log4j Core configuration through the JUL Logger interface. It requires the usage of the Log4j Core implementation.

org.apache.logging.log4j.jul.ApiLoggerAdapter

It disables the level mutators in the JUL Logger interface.

Since version 2.24.0 the default value changed to ApiLoggerAdapter. If you need to modify log levels via JUL, you need to select CoreLoggerAdapter explicitly.

Log4j Spring Boot properties

The Log4j Spring Boot module supports the following configuration properties:

log4j2.disableCloudConfigLoggingSystem

Env. variable

LOG4J_DISABLE_CLOUD_CONFIG_LOGGING_SYSTEM

Type

boolean

Default value

false

Disables the usage of the Spring Boot Log4j2CloudConfigLoggingSystem.

Property sources

The Log4j configuration properties sub-system merges the content of multiple property sources that implement the Java interface PropertySource.

Additional property source classes can be added through:

  • the standard Java SE ServiceLoader mechanism,

  • programmatically using addPropertySource() and removePropertySource() static methods of PropertiesUtil.

Each property source can define its own naming convention for property names, although most of them support the standard:

log4j2.camelCasePropertyName

convention.

Properties can be overridden by sources with a lower numerical priority (e.g. -100 comes before 100).

Log4j provides the following implementations:

Table 1. PropertySource priorities and descriptions
Name Priority Naming Convention Module Description

SpringPropertySource

-100

standard

log4j-spring

Delegates property resolution to a Spring Environment. See Log4j Spring Boot Support for details.

SystemPropertiesPropertySource

0

standard

log4j-api

Resolves properties using Java System Properties.

EnvironmentPropertySource

100

custom

log4j-api

Resolves properties using environment variables.

Warning: The naming convention of this property source differs from the standard one. The property name is prefixed with LOG4J_, is in all caps and words are all separated by underscores.

PropertyFilePropertySource

200

standard

log4j-api

Resolves properties using all the resources named log4j2.component.properties found on the classpath. This property source should be used to change the default values of an application.