AsyncFileHandler (Apache Tomcat 11.0.23 API Documentation)
Description: declaration: package: org.apache.juli, class: AsyncFileHandler

# Class AsyncFileHandler

java.lang.Object
java.util.logging.Handler
org.apache.juli.FileHandler
org.apache.juli.AsyncFileHandler

public class AsyncFileHandler extends FileHandler
A `FileHandler` implementation that uses a queue of log entries.

Configuration properties are inherited from the `FileHandler` class. This class does not add its own configuration properties for the logging configuration, but relies on the following system properties instead:

- `org.apache.juli.AsyncOverflowDropType` Default value: `1`
- `org.apache.juli.AsyncMaxRecordCount` Default value: `10000`

See the System Properties page in the configuration reference of Tomcat.

- ## Nested Class Summary

  ### Nested classes/interfaces inherited from class FileHandler

  `FileHandler.ThreadFactory`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected boolean`
  `closed`
  Indicates whether this handler has been closed.
  `static final int`
  `DEFAULT_MAX_RECORDS`
  Default maximum number of records in the queue.
  `static final int`
  `DEFAULT_OVERFLOW_DROP_TYPE`
  Default overflow drop type value.
  `static final int`
  `MAX_RECORDS`
  Configured maximum record count from system property.
  `static final int`
  `OVERFLOW_DROP_CURRENT`
  Overflow policy: drop the current record.
  `static final int`
  `OVERFLOW_DROP_FIRST`
  Overflow policy: drop the first (oldest) record in the queue.
  `static final int`
  `OVERFLOW_DROP_FLUSH`
  Overflow policy: flush the queue and retry.
  `static final int`
  `OVERFLOW_DROP_LAST`
  Overflow policy: drop the last record in the queue.
  `static final int`
  `OVERFLOW_DROP_TYPE`
  Configured overflow drop type from system property.

  ### Fields inherited from class FileHandler

  `DEFAULT_BUFFER_SIZE, DEFAULT_MAX_DAYS, writerLock`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AsyncFileHandler()`
  Constructs an AsyncFileHandler with default settings.
  `AsyncFileHandler(String directory, String prefix, String suffix)`
  Constructs an AsyncFileHandler with the specified directory, prefix, and suffix.
  `AsyncFileHandler(String directory, String prefix, String suffix, Integer maxDays)`
  Constructs an AsyncFileHandler with the specified directory, prefix, suffix, and max days.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  Close the currently open log file (if any).
  `void`
  `open()`
  Open the new log file for the date specified by `date`.
  `void`
  `publish(LogRecord record)`
  Format and publish a `LogRecord`.
  `protected void`
  `publishInternal(LogRecord record)`
  Publishes a log record to the underlying handler.

  ### Methods inherited from class FileHandler

  `closeWriter, flush, openWriter`

  ### Methods inherited from class Handler

  `getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### OVERFLOW_DROP_LAST

    public static final int OVERFLOW_DROP_LAST
    Overflow policy: drop the last record in the queue.
    See Also:
      - Constant Field Values

  - ### OVERFLOW_DROP_FIRST

    public static final int OVERFLOW_DROP_FIRST
    Overflow policy: drop the first (oldest) record in the queue.
    See Also:
      - Constant Field Values

  - ### OVERFLOW_DROP_FLUSH

    public static final int OVERFLOW_DROP_FLUSH
    Overflow policy: flush the queue and retry.
    See Also:
      - Constant Field Values

  - ### OVERFLOW_DROP_CURRENT

    public static final int OVERFLOW_DROP_CURRENT
    Overflow policy: drop the current record.
    See Also:
      - Constant Field Values

  - ### DEFAULT_OVERFLOW_DROP_TYPE

    public static final int DEFAULT_OVERFLOW_DROP_TYPE
    Default overflow drop type value.
    See Also:
      - Constant Field Values

  - ### DEFAULT_MAX_RECORDS

    public static final int DEFAULT_MAX_RECORDS
    Default maximum number of records in the queue.
    See Also:
      - Constant Field Values

  - ### OVERFLOW_DROP_TYPE

    public static final int OVERFLOW_DROP_TYPE
    Configured overflow drop type from system property.

  - ### MAX_RECORDS

    public static final int MAX_RECORDS
    Configured maximum record count from system property.

  - ### closed

    protected volatile boolean closed
    Indicates whether this handler has been closed.

- ## Constructor Details

  - ### AsyncFileHandler

    public AsyncFileHandler()
    Constructs an AsyncFileHandler with default settings.

  - ### AsyncFileHandler

    public AsyncFileHandler(String directory, String prefix, String suffix)
    Constructs an AsyncFileHandler with the specified directory, prefix, and suffix.
    Parameters:
      `directory` - The directory for log files
      `prefix` - The log file name prefix
      `suffix` - The log file name suffix

  - ### AsyncFileHandler

    public AsyncFileHandler(String directory, String prefix, String suffix, Integer maxDays)
    Constructs an AsyncFileHandler with the specified directory, prefix, suffix, and max days.
    Parameters:
      `directory` - The directory for log files
      `prefix` - The log file name prefix
      `suffix` - The log file name suffix
      `maxDays` - Maximum number of days to keep log files

- ## Method Details

  - ### close

    public void close()
    Description copied from class: `FileHandler`
    Close the currently open log file (if any).
    Overrides:
      `close` in class `FileHandler`

  - ### open

    public void open()
    Description copied from class: `FileHandler`
    Open the new log file for the date specified by `date`.
    Overrides:
      `open` in class `FileHandler`

  - ### publish

    public void publish(LogRecord record)
    Description copied from class: `FileHandler`
    Format and publish a `LogRecord`.
    Overrides:
      `publish` in class `FileHandler`
    Parameters:
      `record` - description of the log event

  - ### publishInternal

    protected void publishInternal(LogRecord record)
    Publishes a log record to the underlying handler.
    Parameters:
      `record` - The log record to publish