Tuesday, April 21, 2009

When to use log.isDebugEnabled()

Logging statements are essential for any standard application. Usually log levels are configured at system level. That is developers just need to write log.debug() statements and forget about while they run or not in various enviornments.

But as a developer, make sure you use log.isDebugEnabled in places where it is appropriate. You don't want to wrap all the log.debug statements. That wont gain you much performance, instead increase code cluttering.

One best place I would suggest is when you try to print a object which has a large toString method with a reflection to string implementation or so.

So,

I use log.debug("Start")

and

if (log.isDebugEnabled()) {
log.debug(complexObject.toString());
}

No comments:

Post a Comment