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 |
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:
and that all the properties names that start with |
Meta configuration properties
In order to rapidly optimize Log4j Core for a particular usage, you can use the following properties:
log4j2.isWebapp
Env. variable |
|
---|---|
Type |
|
Default value |
|
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 |
|
---|---|
Type |
|
Default value |
|
Setting this property to true
switches Log4j Core into "garbage-free mode" ("GC-free mode").
In this mode Log4j uses ThreadLocal
s 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 |
|
---|---|
Type |
|
Default value |
|
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 |
|
---|---|
Type |
|
Default value |
automatically detected |
Since |
|
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 |
|
---|---|
Type |
|
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 Logger
s.
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 |
|
---|---|
Type |
|
Default value |
|
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 |
|
---|---|
Type |
|
Default value |
|
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 |
|
---|---|
Type |
|
Default value |
|
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 |
|
---|---|
Type |
|
Default value |
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 |
|
---|---|
Type |
|
Default value |
(GC-free mode: |
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 |
|
---|---|
Type |
predefined constant |
Default value |
|
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 conditionawait()
call. This ensures that if a notification is missed somehow the consumer thread is not stuck but will recover with a small latency delay, seelog4j2.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 (seelog4j2.asyncLoggerRetries
andlog4j2.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 |
|
---|---|
Type |
|
Default value |
|
Timeout in milliseconds of Timeout
wait strategy (see log4j2.asyncLoggerWaitStrategy
).
log4j2.asyncLoggerSleepTimeNs
Env. variable |
|
---|---|
Type |
|
Default value |
|
Sleep time in nanoseconds of Sleep
wait strategy (see log4j2.asyncLoggerWaitStrategy
).
log4j2.asyncLoggerRetries
Env. variable |
|
---|---|
Type |
|
Default value |
|
Total number of spin cycles and Thread.yield()
cycles of Sleep
(see log4j2.asyncLoggerWaitStrategy
).
log4j2.asyncLoggerSynchronizeEnqueueWhenQueueFull
Env. variable |
|
---|---|
Type |
|
Default value |
|
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 |
|
---|---|
Type |
|
Default value |
|
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 |
|
---|---|
Type |
|
Default value |
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 |
|
---|---|
Type |
|
Default value |
(GC-free mode: |
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 |
|
---|---|
Type |
predefined constant |
Default value |
|
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 conditionawait()
call. This ensures that if a notification is missed somehow the consumer thread is not stuck but will recover with a small latency delay (seelog4j2.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 (seelog4j2.asyncLoggerRetries
andlog4j2.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 |
|
---|---|
Type |
|
Default value |
|
Timeout in milliseconds of Timeout
wait strategy (see log4j2.asyncLoggerConfigWaitStrategy
).
log4j2.asyncLoggerConfigSleepTimeNs
Env. variable |
|
---|---|
Type |
|
Default value |
|
Sleep time in nanoseconds of Sleep
wait strategy (see log4j2.asyncLoggerConfigWaitStrategy
)).
log4j2.asyncLoggerConfigRetries
Env. variable |
|
---|---|
Type |
|
Default value |
|
Total number of spin cycles and Thread.yield()
cycles of Sleep
(see log4j2.asyncLoggerConfigWaitStrategy
)).
log4j2.asyncLoggerConfigSynchronizeEnqueueWhenQueueFull
Env. variable |
|
---|---|
Type |
|
Default value |
|
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 |
|
---|---|
Type |
|
Default value |
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 |
|
---|---|
Type |
|
Default value |
|
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 |
|
---|---|
Type |
|
Default value |
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.
See also Automatic Configuration.
log4j2.level
Env. variable |
|
---|---|
Type |
|
Default value |
|
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 |
|
---|---|
Type |
|
Default value |
Specifies the fully qualified class name of the MergeStrategy
implementation used to merge multiple configuration files into one.
Garbage Collection
log4j2.enableDirectEncoders
Env. variable |
|
---|---|
Type |
|
Default value |
|
If true
, garbage-aware layouts will directly encode log events into ByteBuffer
s provided by appenders.
This prevents allocating temporary String
and char[]
instances.
log4j2.encoderByteBufferSize
Env. variable |
|
---|---|
Type |
|
Default value |
|
The size in bytes of the
ByteBuffer
s
stored in ThreadLocal
fields by layouts and
StringBuilderEncoder
s.
This setting is only used if log4j2.enableDirectEncoders
is set to true
.
log4j2.encoderCharBufferSize
Env. variable |
|
---|---|
Type |
|
Default value |
|
The size in char
s of the
ByteBuffer
s
stored in ThreadLocal
fields
StringBuilderEncoder
s.
This setting is only used if log4j2.enableDirectEncoders
is set to true
.
log4j2.initialReusableMsgSize
Env. variable |
|
---|---|
Type |
|
Default value |
|
In GC-free mode, this property determines the initial size of the reusable StringBuilder
s used by
ReusableMessages
for formatting purposes.
log4j2.maxReusableMsgSize
Env. variable |
|
---|---|
Type |
|
Default value |
|
In GC-free mode, this property determines the maximum size of the reusable StringBuilder
s 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 |
|
---|---|
Type |
|
Default value |
|
This property determines the maximum size of the reusable StringBuilder
s used to format
LogEvent
s.
log4j2.unboxRingbufferSize
Env. variable |
|
---|---|
Type |
|
Default value |
|
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:
JMX
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 |
|
---|---|
Type |
|
Default value |
|
When true
the JndiContextSelector
is enabled for the java:
protocol.
See Web application for more details.
log4j2.enableJndiJdbc
Env. variable |
|
---|---|
Type |
|
Default value |
|
When true
, a Log4j JDBC Appender can use JNDI to retrieve a DataSource
using 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 The |
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 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 |
|
---|---|
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.
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 |
|
---|---|
Type |
Comma-separated list of |
Default value |
|
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 accessfile:
resources, this protocol can not be effectively disabled.
log4j2.configurationAuthorizationProvider
Env. variable |
|
---|---|
Type |
|
Default value |
The fully qualified class name of the
AuthorizationProvider
implementation to use with http
and https
URL protocols.
log4j2.configurationAuthorizationEncoding
Env. variable |
|
---|---|
Type |
|
Default value |
|
The encoding used in Basic Authentication (cf. RFC 7617).
log4j2.configurationPassword
Env. variable |
|
---|---|
Type |
|
Default value |
|
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 |
|
---|---|
Type |
|
Default value |
|
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 |
|
---|---|
Type |
|
Default value |
|
The username used in HTTP Basic authentication.
log4j2.trustStoreLocation
Env. variable |
|
---|---|
Type |
|
Default value |
The location of the trust store.
log4j2.trustStorePassword
Env. variable |
|
---|---|
Type |
|
Default value |
|
The password for the trust store.
log4j2.trustStorePasswordFile
Env. variable |
|
---|---|
Type |
|
Default value |
|
The name of a file that contains the password for the trust store.
log4j2.trustStorePasswordEnvironmentVariable
Env. variable |
|
---|---|
Type |
|
Default value |
|
The name of the environment variable that contains password for the trust store.
log4j2.trustStoreType
Env. variable |
|
---|---|
Type |
|
Default value |
The type of trust store.
log4j2.trustStoreKeyManagerFactoryAlgorithm
Env. variable |
|
---|---|
Type |
|
Default value |
Name of the KeyManagerFactory
implementation to use for the trust store.
log4j2.sslVerifyHostName
Env. variable |
|
---|---|
Type |
|
Default value |
|
If true
enables verification of the name of the TLS server.
log4j2.keyStoreLocation
Env. variable |
|
---|---|
Type |
|
Default value |
The location of the private key store.
log4j2.keyStorePassword
Env. variable |
|
---|---|
Type |
|
Default value |
|
The password for the private key store.
log4j2.keyStorePasswordFile
Env. variable |
|
---|---|
Type |
|
Default value |
|
The name of a file that contains the password for the private key store.
log4j2.keyStorePasswordEnvironmentVariable
Env. variable |
|
---|---|
Type |
|
Default value |
|
The name of the environment variable that contains the password for the private key store.
log4j2.keyStoreType
Env. variable |
|
---|---|
Type |
|
Default value |
The type of private key store.
See KeyStore
.
log4j2.keyStoreKeyManagerFactoryAlgorithm
Env. variable |
|
---|---|
Type |
|
Default value |
Name of the KeyManagerFactory
implementation to use for the private key store.
See KeyManagerFactory
.
Miscellaneous properties
log4j2.clock
Env. variable |
|
---|---|
Type |
|
Default value |
|
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. SeeCoarseCachedClock
for details.
log4j2.contextData
Env. variable |
|
---|---|
Type |
|
Default value |
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 |
|
---|---|
Type |
|
Default value |
depends on the |
Fully qualified class name of a
ContextDataInjector
implementation.
The default implementation uses all implementations of
ContextDataProvider
registered with ServiceLoader
.
log4j2.logEventFactory
Env. variable |
|
---|---|
Type |
|
Default value |
(GC-free mode:
|
Specifies the
LogEventFactory
implementation to use to create log events.
log4j2.reliabilityStrategy
Env. variable |
|
---|---|
Type |
|
Default value |
|
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 |
|
---|---|
Type |
|
Default value |
|
Number of milliseconds to wait before stopping the old configuration if the AwaitUnconditionally
reliability strategy is used.
See log4j2.reliabilityStrategy
.
log4j2.shutdownHookEnabled
Env. variable |
|
---|---|
Type |
|
Default value |
(Web-app mode: |
If true
a shutdown hook will be installed to stop all logger contexts when the system stops.
log4j2.shutdownCallbackRegistry
Env. variable |
|
---|---|
Type |
|
Default value |
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 |
|
---|---|
Type |
|
Default value |
|
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 |
|
---|---|
Type |
|
Default value |
(GC-free mode:
|
Fully qualified class name of a
MessageFactory
implementation that will be used by loggers if no explicit factory was specified.
log4j2.flowMessageFactory
Env. variable |
|
---|---|
Type |
|
Default value |
Fully qualified class name of a
FlowMessageFactory
implementation to be used by all loggers.
log4j2.loggerContextStacktraceOnStart
Env. variable |
|
---|---|
Type |
|
Default value |
|
Prints a stacktrace to the Status Logger at DEBUG
level when the LoggerContext
is started.
For debug purposes only.
log4j2.scriptEnableLanguages
Env. variable |
|
---|---|
Type |
Comma-separated list of |
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 |
|
---|---|
Type |
|
Default value |
|
Fully qualified name of an alternative org.apache.logging.log4j.jul.LevelConverter
implementation.
log4j2.julLoggerAdapter
Env. variable |
|
---|---|
Type |
|
Default value |
|
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 |
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()
andremovePropertySource()
static methods ofPropertiesUtil
.
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:
Name | Priority | Naming Convention | Module | Description |
---|---|---|---|---|
|
standard |
|
Delegates property resolution to a Spring |
|
|
|
standard |
|
Resolves properties using Java System Properties. |
|
|
custom |
|
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. |
|
|
standard |
|
Resolves properties using all the resources named |