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

Best strategy for logging using log4j

 
Viral Limbad
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying out Log4j right now. I want to implement a logging component which will be responsible to log all the important events of the entire web application run.

Can you please suggest me a cool strategy of implementing this so that I can easily generate logs and store them to various file locations and make them Archive too.

I have gone through the API and found nice code that will work great. But I am not able to come up with a GENERIC component for logging. And little confused where to put logging code. Since it�s the first time I am trying LOGGING.

Please help.
 
Paul Michael
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two ways I can think of based on your problem:

One is to create your own logging level and appender, then invoke the log(YourLevel, message) in your classes (this would mark the important events in your application).

Then in your appender, filter out those events which match YourLevel and perform your own custom processing.

Or simply re-use the existing levels (INFO sounds like a good candidate) but you'll be in trouble once other classes in your application starts using this level in their logs inappropriately.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic