Package org.spf4j.log
Class Spf4jAsyncAppender
- java.lang.Object
-
- ch.qos.logback.core.spi.ContextAwareBase
-
- ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
-
- org.spf4j.log.Spf4jAsyncAppender
-
- All Implemented Interfaces:
ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent>,ch.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.ILoggingEvent>,ch.qos.logback.core.spi.ContextAware,ch.qos.logback.core.spi.FilterAttachable<ch.qos.logback.classic.spi.ILoggingEvent>,ch.qos.logback.core.spi.LifeCycle
public class Spf4jAsyncAppender extends ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent> implements ch.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.ILoggingEvent>A custom async implementation, to add statistics about logging. We will record metrics for queued logs and dropped logs. This implementation also eliminated the forever blocking implementation option which makes no sense in any circumstance. (nothing/nobody waits forever)- Author:
- Zoltan Farkas
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAX_FLUSH_TIME_MILLISThe default maximum queue flush time allowed during appender stop.static intDEFAULT_QUEUE_SIZEThe default buffer size.static intUNDEFINED
-
Constructor Summary
Constructors Constructor Description Spf4jAsyncAppender()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAppender(ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent> newAppender)protected voidappend(ch.qos.logback.classic.spi.ILoggingEvent eventObject)Implement/Overwrite to handle log events.voiddetachAndStopAllAppenders()booleandetachAppender(ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent> eAppender)booleandetachAppender(String name)ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent>getAppender(String name)intgetDiscardingThreshold()intgetMaxFlushTimeMillis()longgetMaxLogEnqueueWaitMillis()intgetNumberOfElementsInQueue()Returns the number of elements currently in the blocking queue.intgetQueueSize()intgetRemainingCapacity()The remaining capacity available in the blocking queue.booleanisAttached(ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent> eAppender)protected booleanisDiscardable(ch.qos.logback.classic.spi.ILoggingEvent event)Events of level TRACE, DEBUG and INFO are deemed to be discardable.booleanisIncludeCallerData()Iterator<ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent>>iteratorForAppenders()protected voidpreprocess(ch.qos.logback.classic.spi.ILoggingEvent eventObject)Extend this method for extra pre-processing.voidsetDiscardingThreshold(int discardingThreshold)voidsetIncludeCallerData(boolean includeCallerData)voidsetMaxFlushTimeMillis(int maxFlushTimeMillis)voidsetMaxLogEnqueueWaitMillis(long maxLogEnqueueWaitMillis)voidsetQueueSize(int queueSize)voidstart()voidstop()-
Methods inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toString
-
Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext
-
-
-
-
Field Detail
-
DEFAULT_MAX_FLUSH_TIME_MILLIS
public static final int DEFAULT_MAX_FLUSH_TIME_MILLIS
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:
- Constant Field Values
-
DEFAULT_QUEUE_SIZE
public static final int DEFAULT_QUEUE_SIZE
The default buffer size.- See Also:
- Constant Field Values
-
UNDEFINED
public static final int UNDEFINED
- See Also:
- Constant Field Values
-
-
Method Detail
-
getMaxLogEnqueueWaitMillis
public final long getMaxLogEnqueueWaitMillis()
-
setMaxLogEnqueueWaitMillis
public final void setMaxLogEnqueueWaitMillis(long maxLogEnqueueWaitMillis)
-
isDiscardable
protected boolean isDiscardable(ch.qos.logback.classic.spi.ILoggingEvent event)
Events of level TRACE, DEBUG and INFO are deemed to be discardable.- Parameters:
event-- Returns:
- true if the event is of level TRACE, DEBUG or INFO false otherwise.
-
preprocess
protected void preprocess(ch.qos.logback.classic.spi.ILoggingEvent eventObject)
Extend this method for extra pre-processing.- Parameters:
eventObject-
-
isIncludeCallerData
public final boolean isIncludeCallerData()
-
setIncludeCallerData
public final void setIncludeCallerData(boolean includeCallerData)
-
start
public final void start()
- Specified by:
startin interfacech.qos.logback.core.spi.LifeCycle- Overrides:
startin classch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
-
stop
public final void stop()
- Specified by:
stopin interfacech.qos.logback.core.spi.LifeCycle- Overrides:
stopin classch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
-
append
protected void append(ch.qos.logback.classic.spi.ILoggingEvent eventObject)
Implement/Overwrite to handle log events.- Specified by:
appendin classch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>- Parameters:
eventObject-
-
getQueueSize
public final int getQueueSize()
-
setQueueSize
public final void setQueueSize(int queueSize)
-
getDiscardingThreshold
public final int getDiscardingThreshold()
-
setDiscardingThreshold
public final void setDiscardingThreshold(int discardingThreshold)
-
getMaxFlushTimeMillis
public final int getMaxFlushTimeMillis()
-
setMaxFlushTimeMillis
public final void setMaxFlushTimeMillis(int maxFlushTimeMillis)
-
getNumberOfElementsInQueue
public final int getNumberOfElementsInQueue()
Returns the number of elements currently in the blocking queue.- Returns:
- number of elements currently in the queue.
-
getRemainingCapacity
public final int getRemainingCapacity()
The remaining capacity available in the blocking queue.- Returns:
- the remaining capacity
-
addAppender
public final void addAppender(ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent> newAppender)
- Specified by:
addAppenderin interfacech.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.ILoggingEvent>
-
iteratorForAppenders
public final Iterator<ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent>> iteratorForAppenders()
- Specified by:
iteratorForAppendersin interfacech.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.ILoggingEvent>
-
getAppender
public final ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent> getAppender(String name)
- Specified by:
getAppenderin interfacech.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.ILoggingEvent>
-
isAttached
public final boolean isAttached(ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent> eAppender)
- Specified by:
isAttachedin interfacech.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.ILoggingEvent>
-
detachAndStopAllAppenders
public final void detachAndStopAllAppenders()
- Specified by:
detachAndStopAllAppendersin interfacech.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.ILoggingEvent>
-
detachAppender
public final boolean detachAppender(ch.qos.logback.core.Appender<ch.qos.logback.classic.spi.ILoggingEvent> eAppender)
- Specified by:
detachAppenderin interfacech.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.ILoggingEvent>
-
detachAppender
public final boolean detachAppender(String name)
- Specified by:
detachAppenderin interfacech.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.ILoggingEvent>
-
-