|
Java™ by example!
|
|
|
How do I use the FileHandler?
With a FileHandler, you can log to one or more files. Here is a simple example that writes to one log file in the current directory. The default formatter for FileHandler is XMLFormatter, so every log entry is an XML segment. Main.java:
You can specify the maximum size of a log file along with a pattern that will be used to dynamically determine the name of the log file. For example: Main.java:
The pattern %t/logfiles/Main.%g.log tells the FileHandler to write to the subdirectory logfiles in the temporary directory (%t). It will use a maximum of 10 files with a limit of approx 10K. To determine the the temporary directory on your system, FileHandler will look at the property java.io.tmpdir. (Find out with System.out.println(System.getProperty("java.io.tmpdir"));) This is the directory listing on my system after running the example:
For more information about the patterns that can be used, check here: http://java.sun.com/j2se/1.4/docs/api/java/util/logging/FileHandler.html
Further Information
Author of answer: Joris Van den Bogaert
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|