You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by xav <xa...@eaton.com> on 2014/07/03 11:37:23 UTC
Logging perf
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.
Re: Logging perf
Posted by xav <xa...@eaton.com>.
Hi JB,
Thanks a lot, have a good day
--
View this message in context: http://karaf.922171.n3.nabble.com/Logging-perf-tp4033974p4033977.html
Sent from the Karaf - User mailing list archive at Nabble.com.
Re: Logging perf
Posted by Ryan Moquin <fr...@gmail.com>.
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é" <jb...@nanthrax.net> 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é
> jbonofre@apache.org
> http://blog.nanthrax.net
> Talend - http://www.talend.com
>
Re: Logging perf
Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
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é
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com