On Aug 22, 2006, at 5:11 PM, Martin Cooper wrote:
if (isDebugLoggingEnabled()) {
log.debug("And the answer is: " + expensiveMethodCallHere());
}
I don't know about you, but I'm very thankful for that guard when
debug
logging is disabled (e.g. in production). Without it, I'm going to
make that
expensive method call even if logging is disabled - and then just
throw away
the result after doing nothing in log.debug. Even a lowly toString
() call,
frequently used in debug logging, can get expensive, so it's not
like this
is a corner case.
-1 on getting rid of guards.
I agree that in rare cases you might want to be able to do this
still. But in the vastly more common 2nd case you cite (the
expensive toString() call), that's entirely the point of this. Log
methods take Object.../Object[] and only toString the objects in the
array if the appropriate log level is enabled.
-t