dev@glassfish.java.net

Re: Please consider avoiding concatenated log messages

From: Jerome Dochez <jerome.dochez_at_oracle.com>
Date: Tue, 26 Jul 2011 16:49:08 -0700

in case 1, concatenation happens no matter what since parameters are interpreted before the method is called.
in case 2, there are 3 parameters so no automatic work happens until the log method is called and therefore the fill-in is never done since the log method can quickly determine that the logging level is inappropriate.

but I agree with Bobby, both are slower than just isLoggable call, although case 2 is much better (just parameters push and pop from the stack difference).
 
jerome

On Jul 26, 2011, at 4:07 PM, Byron Nevins wrote:

> What slows it down 7 fold? Is it
>
> Logger.fine(something) versus Logger.log(Level.FINE, something)
>
> Or is it concatenation versus having logger fill-in the {0}
>
> ????????????
>
>
>
> On 7/26/2011 11:02 AM, Bobby Bissett wrote:
>> On 7/26/11 12:52 PM, Vince Kraemer wrote:
>>> Hi all,
>>>
>>> I noticed some lines (about 1350) like this
>>>
>>> logger.fine("some message: " + varForDetail);
>>>
>>> in our code.
>>>
>>> This is 'equal to'
>>>
>>> logger.log(Level.FINE, "some message: {0}", varForDetail);
>>>
>>> but it seems like this second form is about 7 times faster to execute, if the logging level is Level.INFO....
>>
>> They're both slower than:
>>
>> if (logger.isLoggable(Level.FINE)) {
>> // now log something that requires an operation
>> }
>>
>> "Don't do that." :)
>>
>> Cheers,
>> Bobby
>>
>
> --
> <oracle_sig_logo.gif>
> Byron Nevins | Principal MTS
> Phone: +1 6503958992
>
> <green-for-email-sig_0.gif> Oracle is committed to developing practices and products that help protect the environment