Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing logs to a single file from Multiple Classes

 
ankuagar Ag
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic