Use of debug/info etc methods from any logging framework (like log4j) helps you to get important information from your application and helps you analyze problems in the application.
It's helpful to use logging messages as much as possible keeping in mind the information you might need while analyzing some problems. But also there are a few things, one should keep in mind while using them.
Take an example,
List aList = new ArrayList();
//do some operations on list
//print the list contents
log.debug(aList.toString());
You might think that you have used debug method so this rather not so important information will not get printed when log level is more than debug. But, do consider the size of the list. No matter what the debug level is, the toString method will always get executed. In your production environment, though the content of the list will not get printed, but the toString method will always get executed, and depending upon the size of the list, it might take considerable amount of cpu time.
I such cases, one can check the log level and then call the methods, hence triggers only an integer comparison.
if(log.level <= debug)
log.debug(aList.toString());
Sunday, August 24, 2008
Subscribe to:
Posts (Atom)