public class AsyncLogger extends Logger implements com.lmax.disruptor.EventTranslatorVararg<RingBufferLogEvent>
To use AsyncLogger, specify the System property
-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
before you obtain a
Logger, and all Loggers returned by LogManager.getLogger will be AsyncLoggers.
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 AsyncLogger 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.
Logger.LoggerProxy, Logger.PrivateConfig
privateConfig
Constructor and Description |
---|
AsyncLogger(LoggerContext context,
String name,
org.apache.logging.log4j.message.MessageFactory messageFactory,
org.apache.logging.log4j.core.async.AsyncLoggerDisruptor loggerDisruptor)
Constructs an
AsyncLogger with the specified context, name and message factory. |
Modifier and Type | Method and Description |
---|---|
void |
actualAsyncLog(RingBufferLogEvent event)
This method is called by the EventHandler that processes the RingBufferLogEvent in a separate thread.
|
void |
logMessage(String fqcn,
org.apache.logging.log4j.Level level,
org.apache.logging.log4j.Marker marker,
org.apache.logging.log4j.message.Message message,
Throwable thrown) |
void |
translateTo(RingBufferLogEvent event,
long sequence,
Object... args) |
protected void |
updateConfiguration(Configuration newConfig)
Associates this Logger with a new Configuration.
|
addAppender, addFilter, equals, filterCount, get, getAppenders, getContext, getFilters, getLevel, getParent, hashCode, isAdditive, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, removeAppender, setAdditive, setLevel, toString, writeReplace
catching, catching, catching, catchingMsg, checkMessageFactory, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, enter, enter, enter, enter, enter, entry, entry, entry, entryMsg, entryMsg, entryMsg, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, error, exit, exit, exit, exit, exitMsg, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, getMessageFactory, getName, getRecursionDepth, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, info, isDebugEnabled, isDebugEnabled, isEnabled, isEnabled, isErrorEnabled, isErrorEnabled, isFatalEnabled, isFatalEnabled, isInfoEnabled, isInfoEnabled, isTraceEnabled, isTraceEnabled, isWarnEnabled, isWarnEnabled, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, log, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, logMessage, printf, printf, throwing, throwing, throwing, throwingMsg, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, traceEntry, traceEntry, traceEntry, traceEntry, traceEntry, traceExit, traceExit, traceExit, traceExit, traceExit, traceExit, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn
public AsyncLogger(LoggerContext context, String name, org.apache.logging.log4j.message.MessageFactory messageFactory, org.apache.logging.log4j.core.async.AsyncLoggerDisruptor loggerDisruptor)
AsyncLogger
with the specified context, name and message factory.context
- context of this loggername
- name of this loggermessageFactory
- message factory of this loggerloggerDisruptor
- helper class that logging can be delegated to. This object owns the Disruptor.protected void updateConfiguration(Configuration newConfig)
Logger
There are two ways this could be used to guarantee all threads are aware of changes to config.
updateConfiguration
in class Logger
newConfig
- The new Configuration.public void logMessage(String fqcn, org.apache.logging.log4j.Level level, org.apache.logging.log4j.Marker marker, org.apache.logging.log4j.message.Message message, Throwable thrown)
logMessage
in interface org.apache.logging.log4j.spi.ExtendedLogger
logMessage
in class Logger
public void translateTo(RingBufferLogEvent event, long sequence, Object... args)
translateTo
in interface com.lmax.disruptor.EventTranslatorVararg<RingBufferLogEvent>
public void actualAsyncLog(RingBufferLogEvent event)
event
- the event to logCopyright © 1999-2019 The 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.