One caveat to this is that any argument evaluations will still be done
regardless of the log level.  In the example below,
String.valueOf(entry[i]), will always be evaluated before the log level is
checked internally.  If you can't avoid arguments like that as parameters,
it may end up making sense to check the log level on your own.  At worst,
you take a hit with the extra boolean check will be less than an argument
being evaluated unnecesarily.  It can be a matter of preference though.  I
usually wrap anything that has something that will evaluate and is logged
at the debug and info level since they are less likely to be output...

Ryan
On Jul 3, 2014 5:48 AM, "Jean-Baptiste Onofré" <[email protected]> wrote:

> Hi Xav,
>
> the code that test  isDebugEnabled() is valid only for log4j 1.x.
>
> If you use slf4j (provided by Pax Logging):
>
> 1/ you don't have to check the log level (slf4j does it for you)
> 2/ I strongly advice to use
>
> logger.debug("Entry number: {} is {}", i, String.valueOf(entry[i]))
>
> Like this, the Strings are evaluated when required (and not always before
> as in your statement).
>
> Regards
> JB
>
> On 07/03/2014 11:37 AM, xav wrote:
>
>> Hi all,
>>
>> I have done a code review on a OSGI (Karaf) project, and I have a simple
>> question about the logging perf.
>>
>> With the default logger in karaf (pax logging), is there mandatory to test
>> all logger.debug by:
>>
>> if(logger.isDebugEnabled() {
>>     logger.debug("Entry number: " + i + " is " +
>> String.valueOf(entry[i]));
>> }
>>
>> or just write:
>> logger.debug("Entry number: " + i + " is " + String.valueOf(entry[i]));
>>
>> Thanks for answers;
>>
>>
>>
>> --
>> View this message in context: http://karaf.922171.n3.nabble.
>> com/Logging-perf-tp4033974.html
>> Sent from the Karaf - User mailing list archive at Nabble.com.
>>
>>
> --
> Jean-Baptiste Onofré
> [email protected]
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>

Reply via email to