Class SimpleLogFileHandler

java.lang.Object
java.util.logging.Handler
gov.usgs.util.logging.SimpleLogFileHandler

public class SimpleLogFileHandler extends Handler
A java.util.logging style Handler that does daily log rotation by default.
  • Field Details

  • Constructor Details

    • SimpleLogFileHandler

      public SimpleLogFileHandler(File logDirectory)
      Create a default SimpleLogHandler. Uses the system locale to roll log files once a day, and default filename format "log_YYYYMMDD.log".
      Parameters:
      logDirectory - the directory to write log files.
    • SimpleLogFileHandler

      public SimpleLogFileHandler(File logDirectory, SimpleDateFormat filenameFormat)
      Create a SimpleLogHandler with a custom filename format.
      Parameters:
      logDirectory - the directory to write log files.
      filenameFormat - the format for log files. Files are opened as soon as the format output changes for a given log's message.
  • Method Details

    • close

      public void close() throws SecurityException
      Closes the current log file.
      Specified by:
      close in class Handler
      Throws:
      SecurityException
    • flush

      public void flush()
      Attempts to flush any buffered content. If exceptions occur, the stream is closed.
      Specified by:
      flush in class Handler
    • getOutputStream

      protected OutputStream getOutputStream(Date date) throws IOException
      Retrieve the outputstream for the current log file.
      Parameters:
      date - the date of the message about to be logged.
      Returns:
      and OutputStream where the log message may be written.
      Throws:
      IOException - if errors occur.
    • publish

      public void publish(LogRecord record)
      Add a LogRecord to the log file.
      Specified by:
      publish in class Handler
    • main

      public static void main(String[] args) throws Exception
      Testing for handler
      Parameters:
      args - CLI args
      Throws:
      Exception - if error occurs