java.util.logging

Class FileHandler

public class FileHandler extends StreamHandler

A FileHandler publishes log records to a set of log files. A maximum file size can be specified; as soon as a log file reaches the size limit, it is closed and the next file in the set is taken.

Configuration: Values of the subsequent LogManager properties are taken into consideration when a FileHandler is initialized. If a property is not defined, or if it has an invalid value, a default is taken without an exception being thrown.

File Name Patterns: The name and location and log files are specified with pattern strings. The handler will replace the following character sequences when opening log files:

If the pattern string does not contain %g and count is greater than one, the handler will append the string .%g to the specified pattern.

If the handler attempts to open a log file, this log file is being used at the time of the attempt, and the pattern string does not contain %u, the handler will append the string .%u to the specified pattern. This step is performed after any generation number has been appended.

Examples for the GNU platform:

Constructor Summary
FileHandler()
Constructs a FileHandler, taking all property values from the current {@link LogManager LogManager} configuration.
FileHandler(String pattern)
FileHandler(String pattern, boolean append)
FileHandler(String pattern, int limit, int count)
FileHandler(String pattern, int limit, int count, boolean append)
Constructs a FileHandler given the pattern for the location and name of the produced log files, the size limit, the number of log files thorough which the handler will rotate, and the append property.
Method Summary
voidpublish(LogRecord record)

Constructor Detail

FileHandler

public FileHandler()
Constructs a FileHandler, taking all property values from the current {@link LogManager LogManager} configuration.

Throws: java.io.IOException FIXME: The Sun Javadoc says: "if there are IO problems opening the files." This conflicts with the general principle that configuration errors do not prohibit construction. Needs review. SecurityException if a security manager exists and the caller is not granted the permission to control the logging infrastructure.

FileHandler

public FileHandler(String pattern)

FileHandler

public FileHandler(String pattern, boolean append)

FileHandler

public FileHandler(String pattern, int limit, int count)

FileHandler

public FileHandler(String pattern, int limit, int count, boolean append)
Constructs a FileHandler given the pattern for the location and name of the produced log files, the size limit, the number of log files thorough which the handler will rotate, and the append property. All other property values are taken from the current {@link LogManager LogManager} configuration.

Parameters: pattern The pattern for the location and name of the produced log files. See the section on file name patterns for details. If pattern is null, the value is taken from the {@link LogManager LogManager} configuration property java.util.logging.FileHandler.pattern. However, this is a pecularity of the GNU implementation, and Sun's API specification does not mention what behavior is to be expected for null. Therefore, applications should not rely on this feature. limit specifies the number of bytes a log file is approximately allowed to reach before it is closed and the handler switches to the next file in the rotating set. A value of zero means that files can grow without limit. count specifies the number of log files through which this handler cycles. append specifies whether the handler will append log records to existing files (true), or whether the handler will clear log files upon switching to them (false).

Throws: java.io.IOException FIXME: The Sun Javadoc says: "if there are IO problems opening the files." This conflicts with the general principle that configuration errors do not prohibit construction. Needs review. SecurityException if a security manager exists and the caller is not granted the permission to control the logging infrastructure.

FIXME: This seems in contrast to all other handler constructors -- verify this by running tests against the Sun reference implementation.

Method Detail

publish

public void publish(LogRecord record)