org.apache.logging.log4j.core.async
Class AsyncLogger

java.lang.Object
  extended by org.apache.logging.log4j.spi.AbstractLogger
      extended by org.apache.logging.log4j.core.Logger
          extended by org.apache.logging.log4j.core.async.AsyncLogger
All Implemented Interfaces:
Serializable, org.apache.logging.log4j.Logger, org.apache.logging.log4j.spi.ExtendedLogger

public class AsyncLogger
extends Logger

AsyncLogger 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 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.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.Logger
Logger.PrivateConfig
 
Field Summary
 
Fields inherited from class org.apache.logging.log4j.core.Logger
config
 
Fields inherited from class org.apache.logging.log4j.spi.AbstractLogger
CATCHING_MARKER, DEFAULT_MESSAGE_FACTORY_CLASS, ENTRY_MARKER, EXCEPTION_MARKER, EXIT_MARKER, FLOW_MARKER, THROWING_MARKER
 
Constructor Summary
AsyncLogger(LoggerContext context, String name, org.apache.logging.log4j.message.MessageFactory messageFactory)
          Constructs an AsyncLogger with the specified context, name and message factory.
 
Method Summary
 void actualAsyncLog(RingBufferLogEvent event)
          This method is called by the EventHandler that processes the RingBufferLogEvent in a separate thread.
static RingBufferAdmin createRingBufferAdmin(String contextName)
          Creates and returns a new RingBufferAdmin that instruments the ringbuffer of the AsyncLogger.
 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)
           
static void stop()
           
 
Methods inherited from class org.apache.logging.log4j.core.Logger
addAppender, addFilter, filterCount, getAppenders, getContext, getFilters, getLevel, getParent, isAdditive, isEnabled, isEnabled, isEnabled, isEnabled, isEnabled, removeAppender, setAdditive, setLevel, toString
 
Methods inherited from class org.apache.logging.log4j.spi.AbstractLogger
catching, catching, catching, catchingMsg, checkMessageFactory, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, debug, entry, entry, entry, entryMsg, error, error, error, error, error, error, error, error, error, error, error, error, error, error, exit, exit, exit, exitMsg, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, fatal, getMessageFactory, getName, 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, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logIfEnabled, logMessage, logMessage, logMessage, logMessage, printf, printf, throwing, throwing, throwing, throwingMsg, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, trace, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AsyncLogger

public AsyncLogger(LoggerContext context,
                   String name,
                   org.apache.logging.log4j.message.MessageFactory messageFactory)
Constructs an AsyncLogger with the specified context, name and message factory.

Parameters:
context - context of this logger
name - name of this logger
messageFactory - message factory of this logger
Method Detail

logMessage

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)
Specified by:
logMessage in interface org.apache.logging.log4j.spi.ExtendedLogger
Overrides:
logMessage in class Logger

actualAsyncLog

public void actualAsyncLog(RingBufferLogEvent event)
This method is called by the EventHandler that processes the RingBufferLogEvent in a separate thread.

Parameters:
event - the event to log

stop

public static void stop()

createRingBufferAdmin

public static RingBufferAdmin createRingBufferAdmin(String contextName)
Creates and returns a new RingBufferAdmin that instruments the ringbuffer of the AsyncLogger.

Parameters:
contextName - name of the global AsyncLoggerContext


Copyright © 1999-2015 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.