@Plugin(name="asyncLogger", category="Core", printObject=true) public class AsyncLoggerConfig extends LoggerConfig
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.
Modifier and Type | Class and Description |
---|---|
static class |
AsyncLoggerConfig.RootLogger
An asynchronous root Logger.
|
LifeCycle.State
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
Modifier | Constructor and Description |
---|---|
|
AsyncLoggerConfig()
Default constructor.
|
|
AsyncLoggerConfig(String name,
org.apache.logging.log4j.Level level,
boolean additive)
Constructor that sets the name, level and additive values.
|
protected |
AsyncLoggerConfig(String name,
List<AppenderRef> appenders,
Filter filter,
org.apache.logging.log4j.Level level,
boolean additive,
Property[] properties,
Configuration config,
boolean includeLocation) |
Modifier and Type | Method and Description |
---|---|
protected void |
callAppenders(LogEvent event)
Passes on the event to a separate thread that will call
asyncCallAppenders(LogEvent) . |
static LoggerConfig |
createLogger(String additivity,
String levelName,
String loggerName,
String includeLocation,
AppenderRef[] refs,
Property[] properties,
Configuration config,
Filter filter)
Factory method to create a LoggerConfig.
|
RingBufferAdmin |
createRingBufferAdmin(String contextName)
Creates and returns a new
RingBufferAdmin that instruments the
ringbuffer of this AsyncLoggerConfig . |
protected static boolean |
includeLocation(String includeLocationConfigValue) |
void |
start()
Make the Filter available for use.
|
void |
stop()
Cleanup the Filter.
|
addAppender, clearAppenders, createLogger, getAppenderRefs, getAppenders, getFilter, getLevel, getLogEventFactory, getName, getParent, getProperties, isAdditive, isIncludeLocation, log, log, removeAppender, setAdditive, setLevel, setLogEventFactory, setParent, toString
addFilter, hasFilter, isFiltered, removeFilter
equalsImpl, getState, hashCodeImpl, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping
public AsyncLoggerConfig()
public AsyncLoggerConfig(String name, org.apache.logging.log4j.Level level, boolean additive)
name
- The Logger name.level
- The Level.additive
- true if the Logger is additive, false otherwise.protected AsyncLoggerConfig(String name, List<AppenderRef> appenders, Filter filter, org.apache.logging.log4j.Level level, boolean additive, Property[] properties, Configuration config, boolean includeLocation)
protected void callAppenders(LogEvent event)
asyncCallAppenders(LogEvent)
.callAppenders
in class LoggerConfig
public void start()
AbstractFilterable
start
in interface LifeCycle
start
in class AbstractFilterable
public void stop()
AbstractFilterable
stop
in interface LifeCycle
stop
in class AbstractFilterable
public RingBufferAdmin createRingBufferAdmin(String contextName)
RingBufferAdmin
that instruments the
ringbuffer of this AsyncLoggerConfig
.contextName
- name of the LoggerContext
@PluginFactory public static LoggerConfig createLogger(@PluginAttribute(value="additivity") String additivity, @PluginAttribute(value="level") String levelName, @PluginAttribute(value="name") String loggerName, @PluginAttribute(value="includeLocation") String includeLocation, @PluginElement(value="AppenderRef") AppenderRef[] refs, @PluginElement(value="Properties") Property[] properties, @PluginConfiguration Configuration config, @PluginElement(value="Filter") Filter filter)
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.protected static boolean includeLocation(String includeLocationConfigValue)
Copyright © 1999-2021 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.