Pradeep's Blog

Google

Monday, April 10, 2006

Good logging design in java

I had to use java’s logging API in my project. Though lots of the information (API & examples) regarding logging can be found online, most of these examples were very simple. These examples were there to explain only to show how certain things can be done using the logging API. None of these sites really explained how logging could be done for larger projects. I looked into other open source projects like hibernate, to look at how they had done their logging before I could start mine. So with that knowledge of how hibernate has done its logging and from my own experience, here are few tips on logging.

- Its always good to have a separate class that generates the logger object. So that any changes to logging mechanism requires you to make changes in just one place.
- Its also better to have your own Log Formatter class, so that you can create customise logging outputs.
- You may have more than one Logformatter class if you are logging to more than one handler.
- I would also recommend you to have just one handler for one logger (I had more that one handler and it complicates things).

0 Comments:

Post a Comment

<< Home