esuslogo
 [To advertise Java(tm) Events here, contact joris@esus.com!]
banner

Java™
by example!






New @ Esus.com


  gb  In-house search engine for better results!

  gb  Get updates with the esus.com
newsletter!









  Home 
 Browse Categories 
 Ask a Java Question 
 Help 
  For Java Tips & Tricks, subscribe to the esus.com newsletter!
Search Java Q&A, Links, API's:   adv 

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:

This code sample is only viewable to esus.com members
Login or become a member!



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:

This code sample is only viewable to esus.com members
Login or become a member!


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:

This code sample is only viewable to esus.com members
Login or become a member!



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!





Terms of Service | Privacy Policy | Contact

Copyright © 2000-2003 Esus.com - All Rights Reserved 
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. Esus.com is independent of Sun Microsystems, Inc. All other trademarks are the sole property of their respective owners.