Class AsyncAppenderBase<E>

  • Type Parameters:
    E -
    All Implemented Interfaces:
    Appender<E>, AppenderAttachable<E>, ContextAware, FilterAttachable<E>, LifeCycle


    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. 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
    • Field Detail

      • DEFAULT_QUEUE_SIZE

        public static final int DEFAULT_QUEUE_SIZE
        The default buffer size.
        See Also:
        Constant Field Values
      • DEFAULT_MAX_FLUSH_TIME

        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
        See Also:
        Constant Field Values
    • Constructor Detail

      • AsyncAppenderBase

        public AsyncAppenderBase()
    • Method Detail

      • isDiscardable

        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.

        Parameters:
        eventObject -
        Returns:
        - true if the event can be discarded, false otherwise
      • preprocess

        protected void preprocess(E eventObject)
        Pre-process the event prior to queueing. The base class does no pre-processing but sub-classes can override this behavior.
        Parameters:
        eventObject -
      • start

        public void start()
      • stop

        public void stop()
      • append

        protected void append(E eventObject)
      • getQueueSize

        public int getQueueSize()
      • setQueueSize

        public void setQueueSize(int queueSize)
      • getDiscardingThreshold

        public int getDiscardingThreshold()
      • setDiscardingThreshold

        public void setDiscardingThreshold(int discardingThreshold)
      • getMaxFlushTime

        public int getMaxFlushTime()
      • setMaxFlushTime

        public void setMaxFlushTime(int maxFlushTime)
      • getNumberOfElementsInQueue

        public int getNumberOfElementsInQueue()
        Returns the number of elements currently in the blocking queue.
        Returns:
        number of elements currently in the queue.
      • getRemainingCapacity

        public int getRemainingCapacity()
        The remaining capacity available in the blocking queue.
        Returns:
        the remaining capacity
        See Also:
        java.util.concurrent.BlockingQueue#remainingCapacity()}
      • addAppender

        public void addAppender(Appender<E> newAppender)
        Description copied from interface: AppenderAttachable
        Add an appender.
      • iteratorForAppenders

        public Iterator<Appender<E>> iteratorForAppenders()
        Description copied from interface: AppenderAttachable
        Get an iterator for appenders contained in the parent object.
      • isAttached

        public boolean isAttached(Appender<E> eAppender)
        Description copied from interface: AppenderAttachable
        Returns true if the specified appender is in list of attached attached, false otherwise.
      • detachAndStopAllAppenders

        public void detachAndStopAllAppenders()
        Description copied from interface: AppenderAttachable
        Detach and processPriorToRemoval all previously added appenders.
      • detachAppender

        public boolean detachAppender(Appender<E> eAppender)
        Description copied from interface: AppenderAttachable
        Detach the appender passed as parameter from the list of appenders.
      • detachAppender

        public boolean detachAppender(String name)
        Description copied from interface: AppenderAttachable
        Detach the appender with the name passed as parameter from the list of appenders.