Name

FileHandler

Synopsis

This Handler subclass formats LogRecord objects and outputs the resulting strings to a file or to a rotating set of files. Arguments passed to the FileHandler( ) constructor specify which file or files are used, and how they are used. The arguments are optional, and if they are not specified, defaults are obtained through LogManager.getProperty( ) as described below. The constructor arguments are:

pattern

A string containing substitution characters that describes one or more files to use. The substitutions performed to convert this pattern to a filename are described below.

limit

An approximate maximum file size for the log file, or 0 for no limit. If count is set to greater than one, then when a log file reaches this maximum, FileHandler closes it, renames it, and then starts a new log with the original filename.

count

When limit is set to be nonzero, this arguemnt specifies the number of old log files to retain.

append

true if the FileHandler should append to log messages already in the named file, or false if it should overwrite the file.

The pattern argument is the most important of these: it specifies which file or files the FileHandler will write to. FileHandler performs the following substitutions on the specified pattern to convert it to a filename:

For

Substitute

/

The directory separator character for the platform. This means that you can always use a forward slash in your patterns, even on Windows filesystems that use backward slashes.

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.