Package org.spf4j.log

Class 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 int DEFAULT_MAX_FLUSH_TIME_MILLIS
      The default maximum queue flush time allowed during appender stop.
      static int DEFAULT_QUEUE_SIZE
      The default buffer size.
      static int UNDEFINED  
      • Fields inherited from class ch.qos.logback.core.UnsynchronizedAppenderBase

        name, started
      • Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase

        context
    • 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
    • Constructor Detail

      • Spf4jAsyncAppender

        public Spf4jAsyncAppender()
    • 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:
        start in interface ch.qos.logback.core.spi.LifeCycle
        Overrides:
        start in class ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
      • stop

        public final void stop()
        Specified by:
        stop in interface ch.qos.logback.core.spi.LifeCycle
        Overrides:
        stop in class ch.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:
        append in class ch.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:
        addAppender in interface ch.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:
        iteratorForAppenders in interface ch.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:
        getAppender in interface ch.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:
        isAttached in interface ch.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.ILoggingEvent>
      • detachAndStopAllAppenders

        public final void detachAndStopAllAppenders()
        Specified by:
        detachAndStopAllAppenders in interface ch.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:
        detachAppender in interface ch.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.ILoggingEvent>
      • detachAppender

        public final boolean detachAppender​(String name)
        Specified by:
        detachAppender in interface ch.qos.logback.core.spi.AppenderAttachable<ch.qos.logback.classic.spi.ILoggingEvent>