org.apache.logging.log4j.core.appender
Class AsyncAppender

java.lang.Object
  extended by org.apache.logging.log4j.core.AbstractLifeCycle
      extended by org.apache.logging.log4j.core.filter.AbstractFilterable
          extended by org.apache.logging.log4j.core.appender.AbstractAppender
              extended by org.apache.logging.log4j.core.appender.AsyncAppender
All Implemented Interfaces:
Serializable, Appender, Filterable, LifeCycle

@Plugin(name="Async",
        category="Core",
        elementType="appender",
        printObject=true)
public final class AsyncAppender
extends AbstractAppender

Appends to one or more Appenders asynchronously. You can configure an AsyncAppender with one or more Appenders and an Appender to append to if the queue is full. The AsyncAppender does not allow a filter to be specified on the Appender references.

See Also:
Serialized Form

Nested Class Summary
 
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.AbstractLifeCycle
LOGGER
 
Method Summary
 void append(LogEvent logEvent)
          Actual writing occurs here.
static AsyncAppender createAppender(AppenderRef[] appenderRefs, String errorRef, boolean blocking, int size, String name, boolean includeLocation, Filter filter, Configuration config, boolean ignoreExceptions)
          Create an AsyncAppender.
 String[] getAppenderRefStrings()
          Returns the names of the appenders that this asyncAppender delegates to as an array of Strings.
 String getErrorRef()
          Returns the name of the appender that any errors are logged to or null.
 int getQueueCapacity()
           
 int getQueueRemainingCapacity()
           
 boolean isBlocking()
          Returns true if this AsyncAppender will block when the queue is full, or false if events are dropped when the queue is full.
 boolean isIncludeLocation()
          Returns true if this AsyncAppender will take a snapshot of the stack with every log event to determine the class and method where the logging call was made.
 void start()
          Make the Filter available for use.
 void stop()
          Cleanup the Filter.
 
Methods inherited from class org.apache.logging.log4j.core.appender.AbstractAppender
error, error, error, getHandler, getLayout, getName, ignoreExceptions, parseInt, setHandler, toString
 
Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
addFilter, getFilter, hasFilter, isFiltered, removeFilter
 
Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
equalsImpl, getState, hashCodeImpl, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.logging.log4j.core.LifeCycle
getState, isStarted, isStopped
 

Method Detail

start

public void start()
Description copied from class: AbstractFilterable
Make the Filter available for use.

Specified by:
start in interface LifeCycle
Overrides:
start in class AbstractFilterable

stop

public void stop()
Description copied from class: AbstractFilterable
Cleanup the Filter.

Specified by:
stop in interface LifeCycle
Overrides:
stop in class AbstractFilterable

append

public void append(LogEvent logEvent)
Actual writing occurs here.

Parameters:
logEvent - The LogEvent.

createAppender

@PluginFactory
public static AsyncAppender createAppender(@PluginElement(value="AppenderRef")
                                                         AppenderRef[] appenderRefs,
                                                         @PluginAttribute(value="errorRef")@PluginAliases(value="error-ref")
                                                         String errorRef,
                                                         @PluginAttribute(value="blocking",defaultBoolean=true)
                                                         boolean blocking,
                                                         @PluginAttribute(value="bufferSize",defaultInt=128)
                                                         int size,
                                                         @PluginAttribute(value="name")
                                                         String name,
                                                         @PluginAttribute(value="includeLocation",defaultBoolean=false)
                                                         boolean includeLocation,
                                                         @PluginElement(value="Filter")
                                                         Filter filter,
                                                         @PluginConfiguration
                                                         Configuration config,
                                                         @PluginAttribute(value="ignoreExceptions",defaultBoolean=true)
                                                         boolean ignoreExceptions)
Create an AsyncAppender.

Parameters:
appenderRefs - The Appenders to reference.
errorRef - An optional Appender to write to if the queue is full or other errors occur.
blocking - True if the Appender should wait when the queue is full. The default is true.
size - The size of the event queue. The default is 128.
name - The name of the Appender.
includeLocation - whether to include location information. The default is false.
filter - The Filter or null.
config - The Configuration.
ignoreExceptions - If "true" (default) exceptions encountered when appending events are logged; otherwise they are propagated to the caller.
Returns:
The AsyncAppender.

getAppenderRefStrings

public String[] getAppenderRefStrings()
Returns the names of the appenders that this asyncAppender delegates to as an array of Strings.

Returns:
the names of the sink appenders

isIncludeLocation

public boolean isIncludeLocation()
Returns true if this AsyncAppender will take a snapshot of the stack with every log event to determine the class and method where the logging call was made.

Returns:
true if location is included with every event, false otherwise

isBlocking

public boolean isBlocking()
Returns true if this AsyncAppender will block when the queue is full, or false if events are dropped when the queue is full.

Returns:
whether this AsyncAppender will block or drop events when the queue is full.

getErrorRef

public String getErrorRef()
Returns the name of the appender that any errors are logged to or null.

Returns:
the name of the appender that any errors are logged to or null

getQueueCapacity

public int getQueueCapacity()

getQueueRemainingCapacity

public int getQueueRemainingCapacity()


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.