Class NewAsyncAppender

  • All Implemented Interfaces:
    Appender, AppenderAttachable, OptionHandler

    public class NewAsyncAppender
    extends AppenderSkeleton
    implements AppenderAttachable

    An asynchronous appender closely reproducing the behaviour of logback's AsyncAppender.

    See Logback's AsyncAppender documentation for configuration options.

    Here is a sample configuration file for NewAsyncAppender.
     <log4j:configuration debug="true"
                          xmlns:log4j='http://jakarta.apache.org/log4j/'>
    
        <appender name="FILE" class="org.apache.log4j.FileAppender">
          <param name="File"   value="/tmp/foobar.log" />
          <param name="Append" value="false" />
    
          <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-5p %c{2} - %m%n"/>
          </layout>
       </appender>
    
         <appender name="ASYNC" class="org.apache.log4j.NewAsyncAppender">
             <param name="QueueSize" value="512"/>
             <appender-ref ref="FILE"/>
         </appender>
    
         <root>
             <level value="info"/>
             <appender-ref ref="ASYNC"/>
         </root>
    
     </log4j:configuration>
    
    
     

    Note: NewAyncAppedner requires DOMConfigurator, i.e. XML configuration format.

    Since:
    1.2.26
    • Field Detail

      • DEFAULT_QUEUE_SIZE

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

        int queueSize
      • 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
      • maxFlushTime

        int maxFlushTime
      • appenderCount

        java.util.concurrent.atomic.AtomicInteger appenderCount
      • blockingQueue

        java.util.concurrent.BlockingQueue<LoggingEvent> blockingQueue
      • neverBlock

        boolean neverBlock
      • discardingThreshold

        int discardingThreshold
      • includeCallerData

        boolean includeCallerData
    • Constructor Detail

      • NewAsyncAppender

        public NewAsyncAppender()
    • Method Detail

      • isQueueBelowDiscardingThreshold

        public boolean isQueueBelowDiscardingThreshold()
      • isDiscardable

        protected boolean isDiscardable​(LoggingEvent 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​(LoggingEvent eventObject)
      • putUninterruptibly

        private void putUninterruptibly​(LoggingEvent eventObject)
      • close

        public void close()
        Description copied from interface: Appender
        Release any resources allocated within the appender such as file handles, network connections, etc.

        It is a programming error to append to a closed appender.

        Specified by:
        close in interface Appender
      • isClosed

        boolean isClosed()
      • requiresLayout

        public boolean requiresLayout()
        Description copied from interface: Appender
        Configurators call this method to determine if the appender requires a layout. If this method returns true, meaning that layout is required, then the configurator will configure an layout using the configuration information at its disposal. If this method returns false, meaning that a layout is not required, then layout configuration will be skipped even if there is available layout configuration information at the disposal of the configurator..

        In the rather exceptional case, where the appender implementation admits a layout but can also work without it, then the appender should return true.

        Specified by:
        requiresLayout in interface Appender
      • removeAppender

        public void removeAppender​(java.lang.String name)
        Description copied from interface: AppenderAttachable
        Remove the appender with the name passed as parameter from the list of appenders.
        Specified by:
        removeAppender in interface AppenderAttachable
      • 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)
      • setNeverBlock

        public void setNeverBlock​(boolean neverBlock)
      • isNeverBlock

        public boolean isNeverBlock()
      • isIncludeCallerData

        public boolean isIncludeCallerData()
      • setIncludeCallerData

        public void setIncludeCallerData​(boolean includeCallerData)