Class AsyncAppender

All Implemented Interfaces:
Appender, Filterable, LocationAware, LifeCycle, LifeCycle2

@Plugin(name="Async", category="Core", elementType="appender", printObject=true) public final class AsyncAppender extends AbstractAppender
Appends to one or more Appenders asynchronously. You can configure an AsyncAppender with one or more Appenders and an Appender to append to if the queue is full. The AsyncAppender does not allow a filter to be specified on the Appender references.
  • Method Details

    • start

      public void start()
      Description copied from class: AbstractFilterable
      Make the Filter available for use.
      Specified by:
      start in interface LifeCycle
      Overrides:
      start in class AbstractFilterable
    • stop

      public boolean stop(long timeout, TimeUnit timeUnit)
      Description copied from class: AbstractFilterable
      Cleanup the Filter.
      Specified by:
      stop in interface LifeCycle2
      Overrides:
      stop in class AbstractFilterable
      Parameters:
      timeout - the maximum time to wait
      timeUnit - the time unit of the timeout argument
      Returns:
      true if the receiver was stopped cleanly and normally, false otherwise.
    • append

      public void append(LogEvent logEvent)
      Actual writing occurs here.
      Parameters:
      logEvent - The LogEvent.
    • logMessageInCurrentThread

      public void logMessageInCurrentThread(LogEvent logEvent)
      FOR INTERNAL USE ONLY.
      Parameters:
      logEvent - the event to log
    • logMessageInBackgroundThread

      public void logMessageInBackgroundThread(LogEvent logEvent)
      FOR INTERNAL USE ONLY.
      Parameters:
      logEvent - the event to log
    • createAppender

      @Deprecated public static AsyncAppender createAppender(AppenderRef[] appenderRefs, String errorRef, boolean blocking, long shutdownTimeout, int size, String name, boolean includeLocation, Filter filter, Configuration config, boolean ignoreExceptions)
      Deprecated.
      Create an AsyncAppender. This method is retained for backwards compatibility. New code should use the AsyncAppender.Builder instead. This factory will use ArrayBlockingQueueFactory by default as was the behavior pre-2.7.
      Parameters:
      appenderRefs - The Appenders to reference.
      errorRef - An optional Appender to write to if the queue is full or other errors occur.
      blocking - True if the Appender should wait when the queue is full. The default is true.
      shutdownTimeout - How many milliseconds the Appender should wait to flush outstanding log events in the queue on shutdown. The default is zero which means to wait forever.
      size - The size of the event queue. The default is 128.
      name - The name of the Appender.
      includeLocation - whether to include location information. The default is false.
      filter - The Filter or null.
      config - The Configuration.
      ignoreExceptions - If "true" (default) exceptions encountered when appending events are logged; otherwise they are propagated to the caller.
      Returns:
      The AsyncAppender.
    • newBuilder

      @PluginBuilderFactory public static AsyncAppender.Builder newBuilder()
    • getAppenderRefStrings

      public String[] getAppenderRefStrings()
      Returns the names of the appenders that this asyncAppender delegates to as an array of Strings.
      Returns:
      the names of the sink appenders
    • isIncludeLocation

      public boolean isIncludeLocation()
      Returns true if this AsyncAppender will take a snapshot of the stack with every log event to determine the class and method where the logging call was made.
      Returns:
      true if location is included with every event, false otherwise
    • isBlocking

      public boolean isBlocking()
      Returns true if this AsyncAppender will block when the queue is full, or false if events are dropped when the queue is full.
      Returns:
      whether this AsyncAppender will block or drop events when the queue is full.
    • getAppenders

      public List<Appender> getAppenders()
      Gets all Appenders.
      Returns:
      a list of Appenders.
    • getErrorRef

      public String getErrorRef()
      Returns the name of the appender that any errors are logged to or null.
      Returns:
      the name of the appender that any errors are logged to or null
    • getQueueCapacity

      public int getQueueCapacity()
    • getQueueRemainingCapacity

      public int getQueueRemainingCapacity()
    • getQueueSize

      public int getQueueSize()
      Returns the number of elements in the queue.
      Returns:
      the number of elements in the queue.
      Since:
      2.11.1