Datasheet

Property Name Description Default Value
FileHandler.count Specifies how many output 1
files to cycle through.
FileHandler.pattern Pattern used to generate %h/java%u.log
output filenames.
FileHandler.append Boolean value specifying false
whether to append to an
existing file or overwrite it.
The
FileHandler class supports filename patterns, allowing the substitution of paths such as the user’s
home directory or the system’s temporary directory. The forward slash (/) is used as a directory separa-
tor, and this works for both Unix and Windows machines. Also supported is the ability to specify where
the generation number goes in the filename when log files are rotated. These patterns are each prefixed
with a percent sign (%). To include the percent sign in the filename, specify two percent signs (%%). The
following table contains all the valid percent-sign substitutions.
Pattern Description
%t Full path of the system temporary directory
%h Value of the user.home system property
%g Generation number used to distinguish rotated logs
%u Unique number used to resolve process conflicts
For example, if you’re executing this on Windows 95 and specify the filename pattern
%t/app_log.txt,
the
FileHandler class expands this to C:\TEMP\app_log.txt. Note that the %t and %h commands do
not include the trailing forward slash.
The
%u is used to account for when multiple threads/processes will access the same log file. Only one
process can have the file open for writing, so to prevent the loss of logging information, the
%u can be
used to output to a log file that has a similar name to the others. For example, the filename pattern
%t/logfile%u.txt can be specified, and if two processes open this same log file for output, the first
will open
C:\TEMP\logfile0.txt and the second will open C:\TEMP\logfile1.txt.
The
MemoryHandler is a circular buffer in memory. It is intended for use as a quick way to store mes-
sages, so the messages have to be sent to another handler to write them to an external source. Because
the buffer is circular, older log records eventually are overwritten by newer records. Formatting can be
delayed to another
Handler, which makes logging to a MemoryHandler quick. Conditions that will
cause the
MemoryHandler to send data (push data) to another Handler are as follows:
A log record passed in has a level greater than a specified
pushLevel.
Another class calls the push method on the MemoryHandler.
A subclass implements specialized behavior to push data depending on custom criteria.
50
Part I: Thinking Like a Java Developer
05_777106 ch01.qxp 11/28/06 10:43 PM Page 50