Top Description Inners Fields Constructors Methods
ch.qos.logback.core

public Class AsyncAppenderBase<E>

extends UnsynchronizedAppenderBase<E>
implements AppenderAttachable<E>
Class Inheritance
All Implemented Interfaces
ch.qos.logback.core.spi.AppenderAttachable
Imports
ch.qos.logback.core.spi.AppenderAttachable, .AppenderAttachableImpl, ch.qos.logback.core.util.InterruptUtil, java.util.ArrayList, .Iterator, .List, java.util.concurrent.ArrayBlockingQueue, .BlockingQueue

This appender and derived classes, log events asynchronously. In order to avoid loss of logging events, this appender should be closed. It is the user's responsibility to close appenders, typically at the end of the application lifecycle.

This appender buffers events in a BlockingQueue. Worker thread created by this appender takes events from the head of the queue, and dispatches them to the single appender attached to this appender.

Please refer to the logback manual for further information about this appender.

Authors
Ceki Gülcü, Torsten Juergeleit
Since
1.0.4

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
pack-priv AppenderAttachableImpl<E>
pack-priv int
pack-priv BlockingQueue<E>
public static final int
DEFAULT_MAX_FLUSH_TIME

The default maximum queue flush time allowed during appender stop.

public static final int
DEFAULT_QUEUE_SIZE

The default buffer size.

pack-priv int
pack-priv int
pack-priv boolean
pack-priv int
pack-priv static final int
pack-priv AsyncAppenderBase<E>.Worker
Inherited from ch.qos.logback.core.UnsynchronizedAppenderBase:
ALLOWED_REPEATSnamestarted

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
protected void
public void
detachAndStopAllAppenders()

Implements ch.qos.logback.core.spi.AppenderAttachable.detachAndStopAllAppenders.

Detach and processPriorToRemoval all previously added appenders.
public boolean
detachAppender(Appender<E> eAppender)

Implements ch.qos.logback.core.spi.AppenderAttachable.detachAppender.

Detach the appender passed as parameter from the list of appenders.
public boolean
detachAppender(String name)

Implements ch.qos.logback.core.spi.AppenderAttachable.detachAppender.

Detach the appender with the name passed as parameter from the list of appenders.
public Appender<E>
public int
public int
public int

Returns:

number of elements currently in the queue.
getNumberOfElementsInQueue
()

Returns the number of elements currently in the blocking queue.

public int
public int

Returns:

the remaining capacity
getRemainingCapacity
()

The remaining capacity available in the blocking queue.

public boolean
isAttached(Appender<E> eAppender)

Implements ch.qos.logback.core.spi.AppenderAttachable.isAttached.

Returns true if the specified appender is in list of attached, false otherwise.
protected boolean

Returns:

- true if the event can be discarded, false otherwise
isDiscardable
(E eventObject)

Is the eventObject passed as parameter discardable?

public boolean
private boolean
public Iterator<Appender<E>>
iteratorForAppenders()

Implements ch.qos.logback.core.spi.AppenderAttachable.iteratorForAppenders.

Get an iterator for appenders contained in the parent object.
protected void
preprocess(E eventObject)

Pre-process the event prior to queueing.

private void
put(E eventObject)

private void
putUninterruptibly(E eventObject)

public void
setDiscardingThreshold(int discardingThreshold)

public void
setMaxFlushTime(int maxFlushTime)

public void
setNeverBlock(boolean neverBlock)

public void
setQueueSize(int queueSize)

public void
public void
Inherited from ch.qos.logback.core.UnsynchronizedAppenderBase:
addFilterclearAllFiltersdoAppendgetCopyOfAttachedFiltersListgetFilterChainDecisiongetNameisStartedsetNametoString

Field Detail

aaiback to summary
pack-priv AppenderAttachableImpl<E> aai
appenderCountback to summary
pack-priv int appenderCount
blockingQueueback to summary
pack-priv BlockingQueue<E> blockingQueue
DEFAULT_MAX_FLUSH_TIMEback to summary
public static final int DEFAULT_MAX_FLUSH_TIME

The default maximum queue flush time allowed during appender stop. If the worker takes longer than this time it will exit, discarding any remaining items in the queue

DEFAULT_QUEUE_SIZEback to summary
public static final int DEFAULT_QUEUE_SIZE

The default buffer size.

discardingThresholdback to summary
pack-priv int discardingThreshold
maxFlushTimeback to summary
pack-priv int maxFlushTime
neverBlockback to summary
pack-priv boolean neverBlock
queueSizeback to summary
pack-priv int queueSize
UNDEFINEDback to summary
pack-priv static final int UNDEFINED
workerback to summary
pack-priv AsyncAppenderBase<E>.Worker worker

Constructor Detail

AsyncAppenderBaseback to summary
public AsyncAppenderBase()

Method Detail

addAppenderback to summary
public void addAppender(Appender<E> newAppender)

Implements ch.qos.logback.core.spi.AppenderAttachable.addAppender.

Doc from ch.qos.logback.core.spi.AppenderAttachable.addAppender.

Add an appender.

appendback to summary
protected void append(E eventObject)

Implements abstract ch.qos.logback.core.UnsynchronizedAppenderBase.append.

Annotations
@Override
detachAndStopAllAppendersback to summary
public void detachAndStopAllAppenders()

Implements ch.qos.logback.core.spi.AppenderAttachable.detachAndStopAllAppenders.

Doc from ch.qos.logback.core.spi.AppenderAttachable.detachAndStopAllAppenders.

Detach and processPriorToRemoval all previously added appenders.

detachAppenderback to summary
public boolean detachAppender(Appender<E> eAppender)

Implements ch.qos.logback.core.spi.AppenderAttachable.detachAppender.

Doc from ch.qos.logback.core.spi.AppenderAttachable.detachAppender.

Detach the appender passed as parameter from the list of appenders.

detachAppenderback to summary
public boolean detachAppender(String name)

Implements ch.qos.logback.core.spi.AppenderAttachable.detachAppender.

Doc from ch.qos.logback.core.spi.AppenderAttachable.detachAppender.

Detach the appender with the name passed as parameter from the list of appenders.

getAppenderback to summary
public Appender<E> getAppender(String name)

Implements ch.qos.logback.core.spi.AppenderAttachable.getAppender.

Doc from ch.qos.logback.core.spi.AppenderAttachable.getAppender.

Get an appender by name.

getDiscardingThresholdback to summary
public int getDiscardingThreshold()
getMaxFlushTimeback to summary
public int getMaxFlushTime()
getNumberOfElementsInQueueback to summary
public int getNumberOfElementsInQueue()

Returns the number of elements currently in the blocking queue.

Returns:int

number of elements currently in the queue.

getQueueSizeback to summary
public int getQueueSize()
getRemainingCapacityback to summary
public int getRemainingCapacity()

The remaining capacity available in the blocking queue.

See also BlockingQueue#remainingCapacity()

Returns:int

the remaining capacity

isAttachedback to summary
public boolean isAttached(Appender<E> eAppender)

Implements ch.qos.logback.core.spi.AppenderAttachable.isAttached.

Doc from ch.qos.logback.core.spi.AppenderAttachable.isAttached.

Returns true if the specified appender is in list of attached, false otherwise.

isDiscardableback to summary
protected boolean isDiscardable(E eventObject)

Is the eventObject passed as parameter discardable? The base class's implementation of this method always returns 'false' but sub-classes may (and do) override this method.

Note that only if the buffer is nearly full are events discarded. Otherwise, when the buffer is "not full" all events are logged.

Returns:boolean

- true if the event can be discarded, false otherwise

isNeverBlockback to summary
public boolean isNeverBlock()
isQueueBelowDiscardingThresholdback to summary
private boolean isQueueBelowDiscardingThreshold()
iteratorForAppendersback to summary
public Iterator<Appender<E>> iteratorForAppenders()

Implements ch.qos.logback.core.spi.AppenderAttachable.iteratorForAppenders.

Doc from ch.qos.logback.core.spi.AppenderAttachable.iteratorForAppenders.

Get an iterator for appenders contained in the parent object.

preprocessback to summary
protected void preprocess(E eventObject)

Pre-process the event prior to queueing. The base class does no pre-processing but subclasses can override this behavior.

putback to summary
private void put(E eventObject)
putUninterruptiblyback to summary
private void putUninterruptibly(E eventObject)
setDiscardingThresholdback to summary
public void setDiscardingThreshold(int discardingThreshold)
setMaxFlushTimeback to summary
public void setMaxFlushTime(int maxFlushTime)
setNeverBlockback to summary
public void setNeverBlock(boolean neverBlock)
setQueueSizeback to summary
public void setQueueSize(int queueSize)
startback to summary
public void start()

Overrides ch.qos.logback.core.UnsynchronizedAppenderBase.start.

Implements ch.qos.logback.core.spi.LifeCycle.start.

Annotations
@Override
stopback to summary
public void stop()

Overrides ch.qos.logback.core.UnsynchronizedAppenderBase.stop.

Implements ch.qos.logback.core.spi.LifeCycle.stop.

Annotations
@Override
ch.qos.logback.core back to summary

pack-priv Class AsyncAppenderBase.Worker

extends Thread
Class Inheritance

Field Summary

Inherited from java.lang.Thread:
MAX_PRIORITYMIN_PRIORITYNORM_PRIORITY

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

This method is run by the thread when it executes.
Inherited from java.lang.Thread:
activeCountcheckAccessclonecountStackFramescurrentThreaddumpStackenumerategetAllStackTracesgetContextClassLoadergetDefaultUncaughtExceptionHandlergetIdgetNamegetPrioritygetStackTracegetStategetThreadGroupgetUncaughtExceptionHandlerholdsLockinterruptinterruptedisAliveisDaemonisInterruptedisVirtualjoinjoinjoinjoinofPlatformofVirtualonSpinWaitresumesetContextClassLoadersetDaemonsetDefaultUncaughtExceptionHandlersetNamesetPrioritysetUncaughtExceptionHandlersleepsleepsleepstartstartVirtualThreadstopsuspendthreadIdtoStringyield

Constructor Detail

Workerback to summary
pack-priv Worker()

Method Detail

runback to summary
public void run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Doc from java.lang.Thread.run.

This method is run by the thread when it executes. Subclasses of Thread may override this method.

This method is not intended to be invoked directly. If this thread is a platform thread created with a Runnable task then invoking this method will invoke the task's run method. If this thread is a virtual thread then invoking this method directly does nothing.