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
Modifier and TypeClassDescriptionstatic class
AsyncAppender.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, LOGGER
Fields inherited from interface org.apache.logging.log4j.core.Appender
ELEMENT_TYPE, EMPTY_ARRAY
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Actual writing occurs here.static AsyncAppender
createAppender
(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
.int
int
int
Returns the number of elements in the queue.boolean
Returnstrue
if this AsyncAppender will block when the queue is full, orfalse
if events are dropped when the queue is full.boolean
Returnstrue
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
logMessageInBackgroundThread
(LogEvent logEvent) FOR INTERNAL USE ONLY.void
logMessageInCurrentThread
(LogEvent logEvent) FOR INTERNAL USE ONLY.static AsyncAppender.Builder
void
start()
Make the Filter available for use.boolean
Cleanup the Filter.Methods inherited from class org.apache.logging.log4j.core.appender.AbstractAppender
error, error, error, getHandler, getLayout, getName, ignoreExceptions, parseInt, requiresLocation, setHandler, toSerializable, toString
Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
addFilter, getFilter, getPropertyArray, hasFilter, isFiltered, removeFilter, stop
Methods 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:AbstractFilterable
Make the Filter available for use.- Specified by:
start
in interfaceLifeCycle
- Overrides:
start
in classAbstractFilterable
-
stop
Description copied from class:AbstractFilterable
Cleanup the Filter.- Specified by:
stop
in interfaceLifeCycle2
- Overrides:
stop
in 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.Builder
insteadCreate an AsyncAppender. This method is retained for backwards compatibility. New code should use theAsyncAppender.Builder
instead. This factory will useArrayBlockingQueueFactory
by 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()Returnstrue
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()Returnstrue
if this AsyncAppender will block when the queue is full, orfalse
if 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
-
AsyncAppender.Builder
instead