Logging to Files
Grace Software
JavaLog

$Revision: 1.3 $
$Date: 2000/02/02 14:34:23 $

Logging to a File

JavaLog can log events to one or more files using the FileHandler class. To enable logging to a file, use the command line property:
    $ java -Dlog.handler.name.url=file:filename MyClass
This will cause JavaLog to write all events to filename. Here, filename can be either an absolute filename or a relative filename. Absolute files have a path prefix like /tmp/JavaLog/application.log. Relative paths have no path prefix like data/application.log and are relative to the current directory in which the java program is run.

Date Format in Filename

The filename may contain java.text.SimpleDateFormat characters like "%(simple-date-format). For example:

    -Dlog.handler.file.url="file:%(hh:mm:ss).log"

Limiting the file size

If the JavaLog program is a server, it will run for extended periods of time and could eventually create huge log files. JavaLog helps solve this problem by allowing the run time user to specify a maximum file size. When this maximum file size is exceeded, there are a few actions that can be performed. Currently the following actions may be performed:

For example:

    $ java -Dlog.handler.file.url="file:%(hh:mm:ss).log" -Dlog.handler.file.maxsize=1500k -Dlog.handler.file.maxsize.action=new MyClass
In the above example, a FileHandler is established (named "file") that will write to a file using the hour, minute, and second as its name with .log as the extension. It also configures the Handler to limit the file size to 1.5 megabytes and to create a new file each time the size limit is reached.

File Compression

When using log.handler.name.maxsize.action=new, JavaLog will close the current log file when the maxsize is reached and open a new one. At this time, the closed file can be compressed by specifying log.handler.name.compression=compression-type property. Here the compression-type can be zip, gzip, or zlib.

These compression types are assumed if the filename uses the extensions ".gz", ".zip", or ".z" respectively. So, the following example establishes a FileHandler to compress with gzip after the file reaches 1.5 megabytes:

    $ java -Dlog.handler.file.url="file:%(hh:mm:ss).gz" -Dlog.handler.file.maxsize=1500k MyClass
There are a few things to notice here: