Class FileHandler


public final class FileHandler extends StreamHandler
A java.util.logging file handler with support for date patterns in log file name. Log file rotation is based on the file name pattern date format.

Configured by the following properties:

  • [class-name].level -- a minimum log level (Level.ALL)
  • [class-name].filter -- an optional log filter (none)
  • [class-name].formatter -- a log formatter (org.rapidcontext.util.logging.LogFormatter)
  • [class-name].encoding -- an optional encoding (platform default)
  • [class-name].pattern -- a log file name pattern, including the file path ("%t/rapidcontext-%d{yyyy-MM-dd}.log")
  • [class-name].append -- a log append flag (true)

A log file pattern may contain the following special character sequences:

  • "%t" -- the system temporary directory
  • "%h" -- the value of the "user.home" system property
  • "%d" -- the current date (in YYYY-MM-DD format)
  • "%d{...}" -- a generic date and time format (using SimpleDateFormat pattern)
  • "%%" -- a single percent sign "%"
  • Constructor Details

    • FileHandler

      public FileHandler() throws SecurityException, IOException
      Creates a new log file handler using LogManager configuration properties.
      Throws:
      SecurityException - if logging control permission is missing
      IOException - if the configured log file couldn't be created
    • FileHandler

      public FileHandler(String pattern, boolean append) throws SecurityException, IOException
      Creates a new log file handler.
      Parameters:
      pattern - the log file pattern
      append - the append existing file flag
      Throws:
      SecurityException - if logging control permission is missing
      IOException - if the configured log file couldn't be created
  • Method Details

    • open

      protected void open(long now) throws SecurityException, IOException
      Opens the log file if not open or name has changed.
      Parameters:
      now - the current time (in milliseconds)
      Throws:
      SecurityException - if the log stream couldn't be modified
      IOException - if the new log file couldn't be opened
    • publish

      public void publish(LogRecord entry)
      Formats and publishes a log record.
      Overrides:
      publish in class StreamHandler
      Parameters:
      entry - the log entry to publish