Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Logging | Performance Bottleneck?

807607Dec 27 2006 — edited Dec 28 2006
Hi

I had a query about logging. Currently, we use jdk 1.4 and use log4j 1.2.8 for logging. The code goes something like this -
logger.log(LOGLEVEL_DEBUG, METHOD_NAME, "Hello World");
Now, this statement gets executed even if the LOGLEVEL is set to something higher than DEBUG (ERROR in our application). The only thing is that the log is not wriiten to the output. We've got zillions of such statements in our code and I was wondering if this could be a significant performance bottleneck.

The most obvious solution seems to be do something like this -
if (logger.isDebugLoggingEnabled())
{
logger.log(LOGLEVEL_DEBUG, METHOD_NAME, "Hello World");
}
My question is, which is the more expensive operation? Ideally, the loggger.log() method must be checking the logger level somewhere and therefore the if() approach should be better.

Thoughts, comments???

Thanks,
Rajiv
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 25 2007
Added on Dec 27 2006
7 comments
196 views