File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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