File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes Best strategy for logging using log4j Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Best strategy for logging using log4j" Watch "Best strategy for logging using log4j" New topic

Best strategy for logging using log4j

Viral Limbad

Joined: Jul 09, 2008
Posts: 1
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

Joined: Jul 02, 2001
Posts: 697
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.

SCJP 1.2 (89%), SCWCD 1.3 (94%), IBM 486 (90%), SCJA Beta (96%), SCEA (91% / 77%), SCEA 5 P1 (77%), SCBCD 5 (85%)
I agree. Here's the link:
subject: Best strategy for logging using log4j
It's not a secret anymore!