Class FileLoggerOutput

java.lang.Object
org.omegazero.common.logging.FileLoggerOutput
All Implemented Interfaces:
LoggerOutput
Direct Known Subclasses:
RotatingFileLoggerOutput

public class FileLoggerOutput extends Object implements LoggerOutput
A LoggerOutput writing to a file.
Since:
2.10
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    System property org.omegazero.common.logging.logBufferSize
    static final int
    System property org.omegazero.common.logging.saveInterval
    static final boolean
    System property org.omegazero.common.logging.syncFlush
    protected PrintWriter
    The output writer.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new FileLoggerOutput, writing to the given logFile.
    FileLoggerOutput(String logFile, int logBufferBytes, int saveInterval)
    Creates a new FileLoggerOutput, writing to the given logFile.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes this LoggerOutput, flushing any remaining data and freeing resources.
    void
    Flushes any buffered data to the underlying output.
    Returns the file name log messages are written to.
    protected void
    Closes and re-opens the file output stream where data is written to.
    void
    setSyncFlush(boolean syncFlush)
    Sets whether the log buffer should be flushed for every message.
    void
    writeLine(String line, String markup)
    Writes the given log line to this LoggerOutput.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SAVE_INTERVAL

      public static final int SAVE_INTERVAL
      System property org.omegazero.common.logging.saveInterval

      The default interval in seconds between explicit data flushes to the log file.

      Default: 300

    • LOG_BUFFER_BYTES

      public static final int LOG_BUFFER_BYTES
      System property org.omegazero.common.logging.logBufferSize

      The default size of the internal log data buffer.

      Default: 100KB

      Since:
      2.11.0
    • SYNC_FLUSH_DEFAULT

      public static final boolean SYNC_FLUSH_DEFAULT
      System property org.omegazero.common.logging.syncFlush

      Sets the default value for syncFlush.

      Default: false

      Since:
      2.11.0
    • writer

      protected PrintWriter writer
      The output writer.
  • Constructor Details

    • FileLoggerOutput

      public FileLoggerOutput(String logFile) throws IOException
      Creates a new FileLoggerOutput, writing to the given logFile.
      Parameters:
      logFile - The name of the output log file
      Throws:
      IOException - If an IO error occurs while opening the file
      See Also:
    • FileLoggerOutput

      public FileLoggerOutput(String logFile, int logBufferBytes, int saveInterval) throws IOException
      Creates a new FileLoggerOutput, writing to the given logFile.
      Parameters:
      logFile - The name of the output log file
      logBufferBytes - The size of the internal log data buffer. If this value is nonpositive, the default is used
      saveInterval - The save interval. If this value is nonpositive, the default is used
      Throws:
      IOException - If an IO error occurs while opening the file
      Since:
      2.11.0
  • Method Details

    • setSyncFlush

      public void setSyncFlush(boolean syncFlush)
      Sets whether the log buffer should be flushed for every message.
      Parameters:
      syncFlush - true to synchronously flush the log buffer
    • getLogFile

      public String getLogFile()
      Returns the file name log messages are written to.
      Returns:
      The configured log file
    • reopen

      protected void reopen() throws IOException
      Closes and re-opens the file output stream where data is written to.
      Throws:
      IOException
      Since:
      2.11.0
    • writeLine

      public void writeLine(String line, String markup)
      Description copied from interface: LoggerOutput
      Writes the given log line to this LoggerOutput.
      Specified by:
      writeLine in interface LoggerOutput
      Parameters:
      line - The log message
      markup - Special terminal escape sequences used for text markup
    • flush

      public void flush()
      Description copied from interface: LoggerOutput
      Flushes any buffered data to the underlying output.
      Specified by:
      flush in interface LoggerOutput
    • close

      public void close()
      Description copied from interface: LoggerOutput
      Closes this LoggerOutput, flushing any remaining data and freeing resources. After a call to this method, the behavior of other methods in this interfaces is undefined.
      Specified by:
      close in interface LoggerOutput