@Plugin(name="Async", category="Core", elementType="appender", printObject=true) public final class AsyncAppender extends AbstractAppender
Modifier and Type | Class and Description |
---|---|
private class |
AsyncAppender.AsyncThread
Thread that calls the Appenders.
|
static class |
AsyncAppender.Builder<B extends AsyncAppender.Builder<B>> |
LifeCycle.State
Modifier and Type | Field and Description |
---|---|
private AppenderRef[] |
appenderRefs |
private AsyncQueueFullPolicy |
asyncQueueFullPolicy |
private boolean |
blocking |
private Configuration |
config |
private static int |
DEFAULT_QUEUE_SIZE |
private AppenderControl |
errorAppender |
private java.lang.String |
errorRef |
private boolean |
includeLocation |
private java.util.concurrent.BlockingQueue<LogEvent> |
queue |
private int |
queueSize |
private static LogEvent |
SHUTDOWN_LOG_EVENT |
private long |
shutdownTimeout |
private AsyncAppender.AsyncThread |
thread |
private static java.util.concurrent.atomic.AtomicLong |
THREAD_SEQUENCE |
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
ELEMENT_TYPE
Modifier | Constructor and Description |
---|---|
private |
AsyncAppender(java.lang.String name,
Filter filter,
AppenderRef[] appenderRefs,
java.lang.String errorRef,
int queueSize,
boolean blocking,
boolean ignoreExceptions,
long shutdownTimeout,
Configuration config,
boolean includeLocation,
BlockingQueueFactory<LogEvent> blockingQueueFactory,
Property[] properties) |
Modifier and Type | Method and Description |
---|---|
void |
append(LogEvent logEvent)
Actual writing occurs here.
|
static AsyncAppender |
createAppender(AppenderRef[] appenderRefs,
java.lang.String errorRef,
boolean blocking,
long shutdownTimeout,
int size,
java.lang.String name,
boolean includeLocation,
Filter filter,
Configuration config,
boolean ignoreExceptions)
Deprecated.
use
AsyncAppender.Builder instead |
java.lang.String[] |
getAppenderRefStrings()
Returns the names of the appenders that this asyncAppender delegates to as an array of Strings.
|
java.lang.String |
getErrorRef()
Returns the name of the appender that any errors are logged to or
null . |
int |
getQueueCapacity() |
int |
getQueueRemainingCapacity() |
int |
getQueueSize()
Returns the number of elements in the queue.
|
private boolean |
handleInterruptedException(LogEvent memento) |
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 |
logMessageInBackgroundThread(LogEvent logEvent)
FOR INTERNAL USE ONLY.
|
void |
logMessageInCurrentThread(LogEvent logEvent)
FOR INTERNAL USE ONLY.
|
private void |
logToErrorAppenderIfNecessary(boolean appendSuccessful,
LogEvent logEvent) |
static AsyncAppender.Builder |
newBuilder() |
void |
start()
Make the Filter available for use.
|
boolean |
stop(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Cleanup the Filter.
|
private boolean |
transfer(LogEvent memento) |
error, error, error, getHandler, getLayout, getName, ignoreExceptions, parseInt, requiresLocation, setHandler, toSerializable, toString
addFilter, getFilter, getPropertyArray, hasFilter, isFiltered, removeFilter, stop
equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stop
private static final int DEFAULT_QUEUE_SIZE
private static final LogEvent SHUTDOWN_LOG_EVENT
private static final java.util.concurrent.atomic.AtomicLong THREAD_SEQUENCE
private final java.util.concurrent.BlockingQueue<LogEvent> queue
private final int queueSize
private final boolean blocking
private final long shutdownTimeout
private final Configuration config
private final AppenderRef[] appenderRefs
private final java.lang.String errorRef
private final boolean includeLocation
private AppenderControl errorAppender
private AsyncAppender.AsyncThread thread
private AsyncQueueFullPolicy asyncQueueFullPolicy
private AsyncAppender(java.lang.String name, Filter filter, AppenderRef[] appenderRefs, java.lang.String errorRef, int queueSize, boolean blocking, boolean ignoreExceptions, long shutdownTimeout, Configuration config, boolean includeLocation, BlockingQueueFactory<LogEvent> blockingQueueFactory, Property[] properties)
public void start()
AbstractFilterable
start
in interface LifeCycle
start
in class AbstractFilterable
public boolean stop(long timeout, java.util.concurrent.TimeUnit timeUnit)
AbstractFilterable
stop
in interface LifeCycle2
stop
in class AbstractFilterable
timeout
- the maximum time to waittimeUnit
- the time unit of the timeout argumentpublic void append(LogEvent logEvent)
logEvent
- The LogEvent.private boolean transfer(LogEvent memento)
public void logMessageInCurrentThread(LogEvent logEvent)
logEvent
- the event to logpublic void logMessageInBackgroundThread(LogEvent logEvent)
logEvent
- the event to logprivate boolean handleInterruptedException(LogEvent memento)
private void logToErrorAppenderIfNecessary(boolean appendSuccessful, LogEvent logEvent)
@Deprecated public static AsyncAppender createAppender(AppenderRef[] appenderRefs, java.lang.String errorRef, boolean blocking, long shutdownTimeout, int size, java.lang.String name, boolean includeLocation, Filter filter, Configuration config, boolean ignoreExceptions)
AsyncAppender.Builder
insteadAsyncAppender.Builder
instead. This factory will use ArrayBlockingQueueFactory
by default as was the behavior
pre-2.7.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.@PluginBuilderFactory public static AsyncAppender.Builder newBuilder()
public java.lang.String[] getAppenderRefStrings()
public boolean isIncludeLocation()
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.true
if location is included with every event, false
otherwisepublic boolean isBlocking()
true
if this AsyncAppender will block when the queue is full, or false
if events are
dropped when the queue is full.public java.lang.String getErrorRef()
null
.null
public int getQueueCapacity()
public int getQueueRemainingCapacity()
public int getQueueSize()