FileHandler
public
class
FileHandler
extends StreamHandler
| java.lang.Object | |||
| ↳ | java.util.logging.Handler | ||
| ↳ | java.util.logging.StreamHandler | ||
| ↳ | java.util.logging.FileHandler | ||
Simple file logging Handler.
The FileHandler can either write to a specified file, or it can write to a rotating set of files.
For a rotating set of files, as each file reaches a given size limit, it is closed, rotated out, and a new file opened. Successively older files are named by adding "0", "1", "2", etc. into the base filename.
By default buffering is enabled in the IO libraries but each log record is flushed out when it is complete.
By default the XMLFormatter class is used for formatting.
Configuration: By default each FileHandler is initialized using the following LogManager configuration properties where <handler-name> refers to the fully-qualified class name of the handler. If properties are not defined (or have invalid values) then the specified default values are used.
- <handler-name>.level specifies the default level for the Handler (defaults to Level.ALL).
- <handler-name>.filter specifies the name of a Filter class to use (defaults to no Filter).
- <handler-name>.formatter specifies the name of a Formatter class to use (defaults to java.util.logging.XMLFormatter)
- <handler-name>.encoding the name of the character set encoding to use (defaults to the default platform encoding).
- <handler-name>.limit specifies an approximate maximum amount to write (in bytes) to any one file. If this is zero, then there is no limit. (Defaults to no limit).
- <handler-name>.count specifies how many output files to cycle through (defaults to 1).
- <handler-name>.pattern specifies a pattern for generating the output file name. See below for details. (Defaults to "%h/java%u.log").
- <handler-name>.append specifies whether the FileHandler should append onto any existing files (defaults to false).
For example, the properties for FileHandler would be:
- java.util.logging.FileHandler.level=INFO
- java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter
For a custom handler, e.g. com.foo.MyHandler, the properties would be:
- com.foo.MyHandler.level=INFO
- com.foo.MyHandler.formatter=java.util.logging.SimpleFormatter
A pattern consists of a string that includes the following special components that will be replaced at runtime:
- "/" the local pathname separator
- "%t" the system temporary directory
- "%h" the value of the "user.home" system property
- "%g" the generation number to distinguish rotated logs
- "%u" a unique number to resolve conflicts
- "%%" translates to a single pe