This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Writing logs to a single file from Multiple Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Writing logs to a single file from Multiple Classes" Watch "Writing logs to a single file from Multiple Classes" New topic
Author

Writing logs to a single file from Multiple Classes

ankuagar Ag
Greenhorn

Joined: Feb 11, 2011
Posts: 2
Hi,

I have created a CustomLogger class where I am adding file handler stuff to the default Logger. I want to use this logger into rest of my application.

When I am using this logger from two different classes, two log files are generated:

- ApplicationLog.log
- ApplicationLog.log.1

I want the logs to be written in a single file. Is this happening because of multiple threads? Please help.

Here is the Logger Code:

Calling Code (2 Different Class):
CustomLogger.getLogger().info("Dummy Message");
ankuagar Ag
Greenhorn

Joined: Feb 11, 2011
Posts: 2
Got the error with my code.

Was instantiating a new instance of fileHandler every time getLogger is called. This creates a new file since previous file is locked with other handler.

Changed initialization of Logger to a different method and implemented Singleton on the CustomLogger.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing logs to a single file from Multiple Classes
 
Similar Threads
General uneasy feeling about java logging...... or maybe it's just too much eggnog
Help needed on File logging
RAD6/WAS6 Logging config..
can I use a single java.util.logging.logger instance for entire project
java.util.Logging configuration...