Class AsyncLoggerConfig
- All Implemented Interfaces:
Filterable,LocationAware,LifeCycle,LifeCycle2
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 LMAX Disruptor for inter-thread communication.
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 ClassesModifier and TypeClassDescriptionstatic classAsyncLoggerConfig.Builder<B extends AsyncLoggerConfig.Builder<B>>static classAn asynchronous root Logger.Nested classes/interfaces inherited from class org.apache.logging.log4j.core.config.LoggerConfig
LoggerConfig.LevelAndRefs, LoggerConfig.LoggerConfigPredicateNested 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
ROOTFields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAsyncLoggerConfig(String name, List<AppenderRef> appenders, Filter filter, Level level, boolean additive, Property[] properties, Configuration config, boolean includeLocation) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcallAppenders(LogEvent event) static LoggerConfigcreateLogger(boolean additivity, Level level, String loggerName, String includeLocation, AppenderRef[] refs, Property[] properties, Configuration config, Filter filter) Deprecated.static LoggerConfigcreateLogger(String additivity, String levelName, String loggerName, String includeLocation, AppenderRef[] refs, Property[] properties, Configuration config, Filter filter) Deprecated.createRingBufferAdmin(String contextName) Creates and returns a newRingBufferAdminthat instruments the ringbuffer of thisAsyncLoggerConfig.protected static booleanincludeLocation(String includeLocationConfigValue) Deprecated.since 2.25.0.protected voidlog(LogEvent event, LoggerConfig.LoggerConfigPredicate predicate) Logs an event.static <B extends AsyncLoggerConfig.Builder<B>>
Bvoidstart()Make the Filter available for use.booleanCleanup the Filter.Methods inherited from class org.apache.logging.log4j.core.config.LoggerConfig
addAppender, clearAppenders, createLogger, getAppenderRefs, getAppenders, getExplicitLevel, getFilter, getLevel, getLevelAndRefs, getLogEventFactory, getName, getParent, getProperties, getPropertyList, getReliabilityStrategy, hasAppenders, includeLocation, isAdditive, isIncludeLocation, isPropertiesRequireLookup, log, log, log, newBuilder, processLogEvent, removeAppender, requiresLocation, setAdditive, setLevel, setLogEventFactory, setParent, toStringMethods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
addFilter, getPropertyArray, hasFilter, isFiltered, removeFilter, stopMethods 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 Details
-
AsyncLoggerConfig
protected AsyncLoggerConfig(String name, List<AppenderRef> appenders, Filter filter, Level level, boolean additive, Property[] properties, Configuration config, boolean includeLocation)
-
-
Method Details
-
newAsyncBuilder
-
log
Description copied from class:LoggerConfigLogs an event.- Overrides:
login classLoggerConfig- Parameters:
event- The log event.predicate- predicate for which LoggerConfig instances to append to. A null value is equivalent to a true predicate.
-
callAppenders
- Overrides:
callAppendersin classLoggerConfig
-
start
public void start()Description copied from class:AbstractFilterableMake the Filter available for use.- Specified by:
startin interfaceLifeCycle- Overrides:
startin classAbstractFilterable
-
stop
Description copied from class:AbstractFilterableCleanup the Filter.- Specified by:
stopin interfaceLifeCycle2- Overrides:
stopin 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
Creates and returns a newRingBufferAdminthat instruments the ringbuffer of thisAsyncLoggerConfig.- Parameters:
contextName- name of theLoggerContext- Returns:
- a new
RingBufferAdminthat instruments the ringbuffer
-
createLogger
@Deprecated public static LoggerConfig createLogger(String additivity, String levelName, String loggerName, String includeLocation, AppenderRef[] refs, Property[] properties, Configuration config, Filter filter) Deprecated.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.
-
createLogger
@Deprecated public static LoggerConfig createLogger(@PluginAttribute(value="additivity",defaultBoolean=true) boolean additivity, @PluginAttribute("level") Level level, @Required(message="Loggers cannot be configured without a name") @PluginAttribute("name") String loggerName, @PluginAttribute("includeLocation") String includeLocation, @PluginElement("AppenderRef") AppenderRef[] refs, @PluginElement("Properties") Property[] properties, @PluginConfiguration Configuration config, @PluginElement("Filter") Filter filter) Deprecated.Factory method to create a LoggerConfig.- Parameters:
additivity- True if additive, false otherwise.level- 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.
- Since:
- 3.0
-
includeLocation
Deprecated.since 2.25.0. The method will become private in version 3.0.
-
createLogger(boolean, Level, String, String, AppenderRef[], Property[], Configuration, Filter)