Class AsyncLoggerConfig
- java.lang.Object
-
- org.apache.logging.log4j.core.AbstractLifeCycle
-
- org.apache.logging.log4j.core.filter.AbstractFilterable
-
- org.apache.logging.log4j.core.config.LoggerConfig
-
- org.apache.logging.log4j.core.async.AsyncLoggerConfig
-
- All Implemented Interfaces:
Filterable
,LifeCycle
,LifeCycle2
@Plugin(name="asyncLogger", category="Core", printObject=true) public class AsyncLoggerConfig extends LoggerConfig
Asynchronous Logger object that is created via configuration and can be combined with synchronous loggers.AsyncLoggerConfig is a logger designed for high throughput and low latency logging. It does not perform any I/O in the calling (application) thread, but instead hands off the work to another thread as soon as possible. The actual logging is performed in the background thread. It uses the LMAX Disruptor library for inter-thread communication. (http://lmax-exchange.github.com/disruptor/)
To use AsyncLoggerConfig, specify
<asyncLogger>
or<asyncRoot>
in configuration.Note that for performance reasons, this logger does not include source location by default. You need to specify
includeLocation="true"
in the configuration or any %class, %location or %line conversion patterns in your log4j.xml configuration will produce either a "?" character or no output at all.For best performance, use AsyncLoggerConfig with the RandomAccessFileAppender or RollingRandomAccessFileAppender, with immediateFlush=false. These appenders have built-in support for the batching mechanism used by the Disruptor library, and they will flush to disk at the end of each batch. This means that even with immediateFlush=false, there will never be any items left in the buffer; all log events will all be written to disk in a very efficient manner.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AsyncLoggerConfig.RootLogger
An asynchronous root Logger.-
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
AbstractFilterable.Builder<B extends AbstractFilterable.Builder<B>>
-
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
-
-
Field Summary
-
Fields inherited from class org.apache.logging.log4j.core.config.LoggerConfig
ROOT
-
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AsyncLoggerConfig(java.lang.String name, java.util.List<AppenderRef> appenders, Filter filter, Level level, boolean additive, Property[] properties, Configuration config, boolean includeLocation)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
callAppenders(LogEvent event)
Passes on the event to a separate thread that will callasyncCallAppenders(LogEvent)
.static LoggerConfig
createLogger(java.lang.String additivity, java.lang.String levelName, java.lang.String loggerName, java.lang.String includeLocation, AppenderRef[] refs, Property[] properties, Configuration config, Filter filter)
Factory method to create a LoggerConfig.RingBufferAdmin
createRingBufferAdmin(java.lang.String contextName)
Creates and returns a newRingBufferAdmin
that instruments the ringbuffer of thisAsyncLoggerConfig
.protected static boolean
includeLocation(java.lang.String includeLocationConfigValue)
void
start()
Make the Filter available for use.boolean
stop(long timeout, java.util.concurrent.TimeUnit timeUnit)
Cleanup the Filter.-
Methods inherited from class org.apache.logging.log4j.core.config.LoggerConfig
addAppender, clearAppenders, createLogger, createLogger, getAppenderRefs, getAppenders, getFilter, getLevel, getLogEventFactory, getName, getParent, getProperties, getPropertyList, getReliabilityStrategy, isAdditive, isIncludeLocation, isPropertiesRequireLookup, log, log, removeAppender, setAdditive, setLevel, setLogEventFactory, setParent, toString
-
Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
addFilter, hasFilter, isFiltered, removeFilter, stop
-
Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stop
-
-
-
-
Constructor Detail
-
AsyncLoggerConfig
protected AsyncLoggerConfig(java.lang.String name, java.util.List<AppenderRef> appenders, Filter filter, Level level, boolean additive, Property[] properties, Configuration config, boolean includeLocation)
-
-
Method Detail
-
callAppenders
protected void callAppenders(LogEvent event)
Passes on the event to a separate thread that will callasyncCallAppenders(LogEvent)
.- Overrides:
callAppenders
in classLoggerConfig
-
start
public void start()
Description copied from class:AbstractFilterable
Make the Filter available for use.- Specified by:
start
in interfaceLifeCycle
- Overrides:
start
in classAbstractFilterable
-
stop
public boolean stop(long timeout, java.util.concurrent.TimeUnit timeUnit)
Description copied from class:AbstractFilterable
Cleanup the Filter.- Specified by:
stop
in interfaceLifeCycle2
- Overrides:
stop
in classAbstractFilterable
- Parameters:
timeout
- the maximum time to waittimeUnit
- the time unit of the timeout argument- Returns:
- true if the receiver was stopped cleanly and normally, false otherwise.
-
createRingBufferAdmin
public RingBufferAdmin createRingBufferAdmin(java.lang.String contextName)
Creates and returns a newRingBufferAdmin
that instruments the ringbuffer of thisAsyncLoggerConfig
.- Parameters:
contextName
- name of theLoggerContext
- Returns:
- a new
RingBufferAdmin
that instruments the ringbuffer
-
createLogger
@PluginFactory public static LoggerConfig createLogger(@PluginAttribute("additivity") java.lang.String additivity, @PluginAttribute("level") java.lang.String levelName, @PluginAttribute("name") java.lang.String loggerName, @PluginAttribute("includeLocation") java.lang.String includeLocation, @PluginElement("AppenderRef") AppenderRef[] refs, @PluginElement("Properties") Property[] properties, @PluginConfiguration Configuration config, @PluginElement("Filter") Filter filter)
Factory method to create a LoggerConfig.- Parameters:
additivity
- True if additive, false otherwise.levelName
- The Level to be associated with the Logger.loggerName
- The name of the Logger.includeLocation
- "true" if location should be passed downstreamrefs
- An array of Appender names.properties
- Properties to pass to the Logger.config
- The Configuration.filter
- A Filter.- Returns:
- A new LoggerConfig.
-
includeLocation
protected static boolean includeLocation(java.lang.String includeLocationConfigValue)
-
-