Class AsyncAppender
java.lang.Object
org.apache.logging.log4j.core.AbstractLifeCycle
org.apache.logging.log4j.core.filter.AbstractFilterable
org.apache.logging.log4j.core.appender.AbstractAppender
org.apache.logging.log4j.core.appender.AsyncAppender
- All Implemented Interfaces:
Appender,Filterable,LocationAware,LifeCycle,LifeCycle2
@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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAsyncAppender.Builder<B extends AsyncAppender.Builder<B>>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
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGERFields inherited from interface org.apache.logging.log4j.core.Appender
ELEMENT_TYPE, EMPTY_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionvoidActual writing occurs here.static AsyncAppendercreateAppender(AppenderRef[] appenderRefs, String errorRef, boolean blocking, long shutdownTimeout, int size, String name, boolean includeLocation, Filter filter, Configuration config, boolean ignoreExceptions) Deprecated.String[]Returns the names of the appenders that this asyncAppender delegates to as an array of Strings.Gets all Appenders.Returns the name of the appender that any errors are logged to ornull.intintintReturns the number of elements in the queue.booleanReturnstrueif this AsyncAppender will block when the queue is full, orfalseif events are dropped when the queue is full.booleanReturnstrueif 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.voidlogMessageInBackgroundThread(LogEvent logEvent) FOR INTERNAL USE ONLY.voidlogMessageInCurrentThread(LogEvent logEvent) FOR INTERNAL USE ONLY.static AsyncAppender.Builderbooleanvoidstart()Make the Filter available for use.booleanCleanup the Filter.Methods inherited from class org.apache.logging.log4j.core.appender.AbstractAppender
error, error, error, getHandler, getLayout, getName, ignoreExceptions, parseInt, setHandler, toSerializable, toStringMethods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
addFilter, getFilter, 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
-
Method Details
-
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.
-
append
Actual writing occurs here.- Parameters:
logEvent- The LogEvent.
-
logMessageInCurrentThread
FOR INTERNAL USE ONLY.- Parameters:
logEvent- the event to log
-
logMessageInBackgroundThread
FOR INTERNAL USE ONLY.- Parameters:
logEvent- the event to log
-
createAppender
@Deprecated public static AsyncAppender createAppender(AppenderRef[] appenderRefs, String errorRef, boolean blocking, long shutdownTimeout, int size, String name, boolean includeLocation, Filter filter, Configuration config, boolean ignoreExceptions) Deprecated.useAsyncAppender.BuilderinsteadCreate an AsyncAppender. This method is retained for backwards compatibility. New code should use theAsyncAppender.Builderinstead. This factory will useArrayBlockingQueueFactoryby default as was the behavior pre-2.7.- 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.shutdownTimeout- How many milliseconds the Appender should wait to flush outstanding log events in the queue on shutdown. The default is zero which means to wait forever.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.
-
newBuilder
-
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()Returnstrueif 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:
trueif location is included with every event,falseotherwise
-
isBlocking
public boolean isBlocking()Returnstrueif this AsyncAppender will block when the queue is full, orfalseif events are dropped when the queue is full.- Returns:
- whether this AsyncAppender will block or drop events when the queue is full.
-
getAppenders
Gets all Appenders.- Returns:
- a list of Appenders.
-
getErrorRef
Returns the name of the appender that any errors are logged to ornull.- Returns:
- the name of the appender that any errors are logged to or
null
-
getQueueCapacity
public int getQueueCapacity() -
getQueueRemainingCapacity
public int getQueueRemainingCapacity() -
getQueueSize
public int getQueueSize()Returns the number of elements in the queue.- Returns:
- the number of elements in the queue.
- Since:
- 2.11.1
-
requiresLocation
public boolean requiresLocation()- Specified by:
requiresLocationin interfaceLocationAware- Overrides:
requiresLocationin classAbstractAppender
-
AsyncAppender.Builderinstead