java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.UnsynchronizedAppenderBase<E>
ch.qos.logback.core.AsyncAppenderBase<E>
- Type Parameters:
E-
- All Implemented Interfaces:
Appender<E>,AppenderAttachable<E>,ContextAware,FilterAttachable<E>,LifeCycle
- Direct Known Subclasses:
AsyncAppender
public class AsyncAppenderBase<E>
extends UnsynchronizedAppenderBase<E>
implements AppenderAttachable<E>
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. AsyncAppenderBase<E>.ch.qos.logback.core.AsyncAppenderBase.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.
- Since:
- 1.0.4
- Author:
- Ceki Gülcü, Torsten Juergeleit
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default maximum queue flush time allowed during appender stop.static final intThe default buffer size.Fields inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
name, startedFields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAppender(Appender<E> newAppender) Add an appender.protected voidvoidDetach and processPriorToRemoval all previously added appenders.booleandetachAppender(Appender<E> eAppender) Detach the appender passed as parameter from the list of appenders.booleandetachAppender(String name) Detach the appender with the name passed as parameter from the list of appenders.getAppender(String name) Get an appender by name.intintintReturns the number of elements currently in the blocking queue.intintThe remaining capacity available in the blocking queue.booleanisAttached(Appender<E> eAppender) Returnstrueif the specified appender is in list of attached,falseotherwise.protected booleanisDiscardable(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.booleanbooleanGet an iterator for appenders contained in the parent object.protected voidpreprocess(E eventObject) Pre-process the event prior to queueing.voidsetDiscardingThreshold(int discardingThreshold) voidsetMaxFlushTime(int maxFlushTime) voidsetNeverBlock(boolean neverBlock) voidsetQueueSize(int queueSize) voidstart()voidstop()Methods inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toStringMethods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ch.qos.logback.core.spi.ContextAware
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext
-
Field Details
-
DEFAULT_QUEUE_SIZE
-
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- See Also:
-
-
Constructor Details
-
AsyncAppenderBase
public AsyncAppenderBase()
-
-
Method Details
-
isDiscardable
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.
- Parameters:
eventObject-- Returns:
- - true if the event can be discarded, false otherwise
-
preprocess
Pre-process the event prior to queueing. The base class does no pre-processing but subclasses can override this behavior.- Parameters:
eventObject-
-
start
-
stop
-
append
- Specified by:
appendin classUnsynchronizedAppenderBase<E>
-
isQueueBelowDiscardingThreshold
-
getQueueSize
-
setQueueSize
-
getDiscardingThreshold
-
setDiscardingThreshold
-
getMaxFlushTime
-
setMaxFlushTime
-
getNumberOfElementsInQueue
Returns the number of elements currently in the blocking queue.- Returns:
- number of elements currently in the queue.
-
setNeverBlock
-
isNeverBlock
-
getRemainingCapacity
The remaining capacity available in the blocking queue.See also
BlockingQueue#remainingCapacity()- Returns:
- the remaining capacity
-
addAppender
Description copied from interface:AppenderAttachableAdd an appender.- Specified by:
addAppenderin interfaceAppenderAttachable<E>
-
iteratorForAppenders
Description copied from interface:AppenderAttachableGet an iterator for appenders contained in the parent object.- Specified by:
iteratorForAppendersin interfaceAppenderAttachable<E>
-
getAppender
Description copied from interface:AppenderAttachableGet an appender by name.- Specified by:
getAppenderin interfaceAppenderAttachable<E>
-
isAttached
Description copied from interface:AppenderAttachableReturnstrueif the specified appender is in list of attached,falseotherwise.- Specified by:
isAttachedin interfaceAppenderAttachable<E>
-
detachAndStopAllAppenders
Description copied from interface:AppenderAttachableDetach and processPriorToRemoval all previously added appenders.- Specified by:
detachAndStopAllAppendersin interfaceAppenderAttachable<E>
-
detachAppender
Description copied from interface:AppenderAttachableDetach the appender passed as parameter from the list of appenders.- Specified by:
detachAppenderin interfaceAppenderAttachable<E>
-
detachAppender
Description copied from interface:AppenderAttachableDetach the appender with the name passed as parameter from the list of appenders.- Specified by:
detachAppenderin interfaceAppenderAttachable<E>
-