[infinispan-dev] trace vs log.isTraceEnabled

Sanne Grinovero sanne at infinispan.org
Wed Dec 7 07:07:41 EST 2011


On 7 December 2011 12:04, Bela Ban <bban at redhat.com> wrote:
>
>
> On 12/7/11 12:56 PM, Sanne Grinovero wrote:
>> On 7 December 2011 11:19, Bela Ban<bban at redhat.com>  wrote:
>>> If you use a constant, this is not an issue, but what about:
>>>
>>> String constant="Error message bla bla";
>>> for(int i=1; i<=10; i++) {
>>> Â  Â log.trace(constant + "-" + i);
>>> }
>>>
>>> ?
>>
>> That should definitely be rewritten as
>>
>> String constant="Error message bla bla";
>> if (log.isTraceEnabled()) {
>>     final String constant="Error message bla bla";
>>     for(int i=1; i<=10; i++) {
>>        log.trace(constant + "-" + i);
>>     }
>> }
>
>
>
> No ! My example was meant to show a loop with *many* statements; one of
> them being a log.trace() !
>
> E.g.
>
> for(......) {
>
> ...
>
> log.trace();
>
> ...
> }

sorry :)
Well then this way:

final boolean trace = log.isTraceEnabled();
for(int i=1; i<=10; i++) {
 ....//other statements
   if (trace) log.trace( ...{preferrabily a JBLogger format}... );
   ...//other statements
}



More information about the infinispan-dev mailing list