Package gov.usgs.util.logging
Class SimpleLogFileHandler
- java.lang.Object
-
- java.util.logging.Handler
-
- gov.usgs.util.logging.SimpleLogFileHandler
-
public class SimpleLogFileHandler extends java.util.logging.Handler
A java.util.logging style Handler that does daily log rotation by default.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_FILENAME_FORMAT
Default format used.
-
Constructor Summary
Constructors Constructor Description SimpleLogFileHandler(java.io.File logDirectory)
Create a default SimpleLogHandler.SimpleLogFileHandler(java.io.File logDirectory, java.text.SimpleDateFormat filenameFormat)
Create a SimpleLogHandler with a custom filename format.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the current log file.void
flush()
Attempts to flush any buffered content.protected java.io.OutputStream
getOutputStream(java.util.Date date)
Retrieve the outputstream for the current log file.static void
main(java.lang.String[] args)
Testing for handlervoid
publish(java.util.logging.LogRecord record)
Add a LogRecord to the log file.
-
-
-
Field Detail
-
DEFAULT_FILENAME_FORMAT
public static final java.lang.String DEFAULT_FILENAME_FORMAT
Default format used.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SimpleLogFileHandler
public SimpleLogFileHandler(java.io.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(java.io.File logDirectory, java.text.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 Detail
-
close
public void close() throws java.lang.SecurityException
Closes the current log file.- Specified by:
close
in classjava.util.logging.Handler
- Throws:
java.lang.SecurityException
-
flush
public void flush()
Attempts to flush any buffered content. If exceptions occur, the stream is closed.- Specified by:
flush
in classjava.util.logging.Handler
-
getOutputStream
protected java.io.OutputStream getOutputStream(java.util.Date date) throws java.io.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:
java.io.IOException
- if errors occur.
-
publish
public void publish(java.util.logging.LogRecord record)
Add a LogRecord to the log file.- Specified by:
publish
in classjava.util.logging.Handler
-
main
public static void main(java.lang.String[] args) throws java.lang.Exception
Testing for handler- Parameters:
args
- CLI args- Throws:
java.lang.Exception
- if error occurs
-
-