Class FileLogHandler

java.lang.Object
java.util.logging.Handler
io.github.connellite.logger.FileLogHandler
Direct Known Subclasses:
AsyncFileLogHandler

public class FileLogHandler extends Handler
Handler that appends one line per LogRecord using the configured Formatter (default SimpleFormatter when FileLogHandlerConfig.formatter() is null). Optional rotation renames the current file to name.log.0, shifts older segments, and starts a new file.

publish(java.util.logging.LogRecord) holds the read side of writerLock while a record is written. Rotation and close() hold the write side: while Files.move(java.nio.file.Path, java.nio.file.Path, java.nio.file.CopyOption...) runs, other threads block (async rotation is out of scope). Byte writes themselves are serialized on streamLock, because the stream is not safe for concurrent use.

  • Constructor Details

  • Method Details

    • publish

      public void publish(LogRecord record)
      Formats the record, rotates when the calendar day or the size limit says so, then appends one line. Formatting runs before rotation, so a formatter failure does not rotate the file.

      Tomcat reference: https://github.com/apache/tomcat/blob/05b5d70555068a6647226e9924b2d7f1b9978b03/java/org/apache/juli/FileHandler.java

      Specified by:
      publish in class Handler
    • flush

      public void flush()
      Flushes the open writer. Does nothing when the file has not been opened yet.

      Tomcat reference: https://github.com/apache/tomcat/blob/05b5d70555068a6647226e9924b2d7f1b9978b03/java/org/apache/juli/FileHandler.java

      Specified by:
      flush in class Handler
    • close

      public void close()
      Closes the open log file.

      Tomcat reference: https://github.com/apache/tomcat/blob/05b5d70555068a6647226e9924b2d7f1b9978b03/java/org/apache/juli/FileHandler.java

      Specified by:
      close in class Handler