[Swift-devel] log4j isLevelEnabled()
Mihael Hategan
hategan at mcs.anl.gov
Fri May 27 13:54:50 CDT 2011
A bit of trivia on the use of:
if (logger.isDebugEnabled()) {
logger.debug("There are " + n + " birds on pole " + p);
}
While it may appear as unnecessary to add the if statement (and
functionally it is unnecessary), the main reason for it is that if the
above appears in some often invoked piece of code, and debug is
disabled, the "if" check can be very quick, whereas without the if, that
check has to happen anyway, but in addition, since the debug() method is
only invoked after its arguments have been constructed, it involves an
additional string creation (which in some cases may involve complex
calls to some custom toString()), etc. So without the "if" it is likely
slower and it unnecessarily involves the heap.
The only case when this would be the worse choice is when the string
passed to debug() was not the result of a concatenation (e.g.
logger.debug("No birds")).
More information about the Swift-devel
mailing list