File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Logger question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Logger question" Watch "Logger question" New topic

Logger question

Payam Fard
Ranch Hand

Joined: Jan 31, 2003
Posts: 75
Hi all,
I have a program with multiple processes. Each process spawn multiple threads. If I want each process to have a unique log file name (all threads associated with a process should write to the same log file), how would I go about doing this to gaurantee uniqueness?
I am mostly looking for setting the name of the log file dynamically in my program rather than using file. Since I want each process to be able to specify its name as part of the logger name. For example if there are 3 processes in the system named two Servers and Client, log names should be something like:
Thank you,
Payam Fard
Ranch Hand

Joined: Jan 31, 2003
Posts: 75
Here is how I am doing it using file:
# default file output is in user's home directory.
java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.formatter =
java.util.logging.FileHandler.append = true
java.util.logging.FileHandler.level = FINE

Now, the log file names are all unique, but are names java0.log, java1.log, java2.log. If there is a way to somehow change the above pattern to include the name of the class that starts the process, it would be great.
I agree. Here's the link:
subject: Logger question
It's not a secret anymore!