An explanation why the "log.isDebugEnabled()" was there and why it
should be added again (maybe not necessarily in this case since it's
only called once per page but as a general rule):

"+" operations with Strings usually results in a StringBuffer being
created the two Strings before and after the operator being combined and
then converted to a String object again. If you have multiple "+"
operator it depends on the intelligence of the JIT compiler whether it
creates only one StringBuffer or one for each "+" operation. Older VMs
always created multiple StringBuffers.

What happens without the isDebugEnabled() is that the combined String is
always (!) built (possibly multiple new String and StringBuffer
instances as well as possibly multiple calls to other methods for
building te String) and then passed into the debug() method. Only then
will the logging implementation check if the log level is sufficient to
output the log statement.

General rule of thumb: Always surround a debug log statement with a
isDebugEnabled() check if the log statement is non-trivial (i.e.
not a simple constant String).

More information:
http://jakarta.apache.org/commons/logging/api/org/apache/commons/logging/Log.html
http://logging.apache.org/log4j/docs/manual.html#performance
http://excalibur.apache.org/apidocs/org/apache/avalon/framework/logger/Logger.html
https://www.qos.ch/ac2001/F11-190.html

On 06.06.2005 07:46:00 gmazza wrote:
>   -        if (log.isDebugEnabled()) {
>   -            log.debug("[" + curPV.getPageNumberString() + (bIsBlank ? "*" 
> : "") + "]");
>   -        }
>   -
>   -        curPV.createSpan(false);
>   +        log.debug("[" + curPV.getPageNumberString() + (bIsBlank ? "*" : 
> "") + "]");
>            return curPV;


Jeremias Maerki

Reply via email to