Package de.stefanfrings.utils
Class BufferedAppender<E>
java.lang.Object
ch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.AppenderBase<E>
de.stefanfrings.utils.BufferedAppender<E>
- All Implemented Interfaces:
ch.qos.logback.core.Appender<E>,ch.qos.logback.core.spi.AppenderAttachable<E>,ch.qos.logback.core.spi.ContextAware,ch.qos.logback.core.spi.FilterAttachable<E>,ch.qos.logback.core.spi.LifeCycle
public class BufferedAppender<E>
extends ch.qos.logback.core.AppenderBase<E>
implements ch.qos.logback.core.spi.AppenderAttachable<E>
For Logback: Write debug messages only when an error occurs.
This appender holds back debug messages in a buffer and writes them only out when an error occurs.
For more flexibility, the BufferedAppender does not write to a file itself. It must be chained with another Appender to produce output.
You should clear the buffer at the beginning or end of each HTTP request, to ensure that the buffer does not contain old stuff when processing the next HTTP request.
- Author:
- Stefan Frings, http://stefanfrings.de/javautils
-
Field Summary
Fields inherited from class ch.qos.logback.core.AppenderBase
name, startedFields inherited from class ch.qos.logback.core.spi.ContextAwareBase
context -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAppender(ch.qos.logback.core.Appender<E> newAppender) protected voidThis method is called when a log message got produced.intstatic voidDiscard buffered messages of the current thread.voidbooleandetachAppender(ch.qos.logback.core.Appender<E> appender) booleandetachAppender(String name) ch.qos.logback.core.Appender<E>getAppender(String name) booleanisAttached(ch.qos.logback.core.Appender<E> appender) voidvoidsetBufferSize(int size) Set buffer size.voidMethods inherited from class ch.qos.logback.core.AppenderBase
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, start, stop, 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
-
Constructor Details
-
BufferedAppender
public BufferedAppender()Constructor
-
-
Method Details
-
clearBuffer
public static void clearBuffer()Discard buffered messages of the current thread. -
append
This method is called when a log message got produced. It buffers debug/trace messages until a warning/error occurs.- Specified by:
appendin classch.qos.logback.core.AppenderBase<E>
-
setAllowedLevel
-
setTriggerLevel
-
setBufferSize
public void setBufferSize(int size) Set buffer size.- Parameters:
size- Maximum number of buffered messages for each thread
-
addAppender
- Specified by:
addAppenderin interfacech.qos.logback.core.spi.AppenderAttachable<E>
-
appendLoopOnAppenders
-
iteratorForAppenders
- Specified by:
iteratorForAppendersin interfacech.qos.logback.core.spi.AppenderAttachable<E>
-
getAppender
- Specified by:
getAppenderin interfacech.qos.logback.core.spi.AppenderAttachable<E>
-
isAttached
- Specified by:
isAttachedin interfacech.qos.logback.core.spi.AppenderAttachable<E>
-
detachAndStopAllAppenders
public void detachAndStopAllAppenders()- Specified by:
detachAndStopAllAppendersin interfacech.qos.logback.core.spi.AppenderAttachable<E>
-
detachAppender
- Specified by:
detachAppenderin interfacech.qos.logback.core.spi.AppenderAttachable<E>
-
detachAppender
- Specified by:
detachAppenderin interfacech.qos.logback.core.spi.AppenderAttachable<E>
-