You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by __matthewHawthorne <ma...@phreaker.net> on 2003/10/30 23:16:37 UTC

[logging] logic for determing log level

This is a general use question about [logging].  I'm looking through the 
source for [betwixt], and I see lines like the following:

if ( log.isTraceEnabled() ) {
   log.trace( "Is " + descriptor + " empty?" );
}

What is the purpose of doing this check?  If trace *is* enabled, then 
isn't the same check done inside of the underlying logging implementation?

Is this some type of trick to improve performance?  I'm probably 
misunderstanding it, but I just think that it adds clutter.

Any insights?



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [logging] logic for determing log level

Posted by Rodney Waldhoff <rw...@apache.org>.
Assuming the if() clause isn't there, then:

  "Is " + descriptor + " empty?"

is evaluated before the call to log.trace(), whether or not that call will
actually yield any output.  Putting the if() { } around it prevents the
arguments to log.trace() from being executed if log.isTraceEnabled() is
false.

See
<http://jakarta.apache.org/log4j/docs/api/org/apache/log4j/Category.html#isDebugEnabled()>
for example.

On Thu, 30 Oct 2003, __matthewHawthorne wrote:

> This is a general use question about [logging].  I'm looking through the
> source for [betwixt], and I see lines like the following:
>
> if ( log.isTraceEnabled() ) {
>    log.trace( "Is " + descriptor + " empty?" );
> }
>
> What is the purpose of doing this check?  If trace *is* enabled, then
> isn't the same check done inside of the underlying logging implementation?
>
> Is this some type of trick to improve performance?  I'm probably
> misunderstanding it, but I just think that it adds clutter.
>
> Any insights?
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>

-- 
- Rod <http://radio.weblogs.com/0122027/>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


RE: [logging] logic for determing log level

Posted by Steve Raeburn <sr...@apache.org>.
In this case you would save the cost of concatenating the Strings and
the descriptor.toString() operation.
You need to figure out if that is a big cost where the code is going to
be used.

Log4J has a faq entry that discusses this subject:
http://jakarta.apache.org/log4j/docs/FAQ.html#fastLogging

Steve

> -----Original Message-----
> From: David Graham [mailto:grahamdavid1980@yahoo.com]
> Sent: October 30, 2003 2:40 PM
> To: Jakarta Commons Developers List
> Subject: Re: [logging] logic for determing log level
>
>
>
> --- __matthewHawthorne <ma...@phreaker.net> wrote:
> > This is a general use question about [logging].  I'm
> looking through the
> >
> > source for [betwixt], and I see lines like the following:
> >
> > if ( log.isTraceEnabled() ) {
> >    log.trace( "Is " + descriptor + " empty?" );
> > }
> >
> > What is the purpose of doing this check?  If trace *is*
> enabled, then
> > isn't the same check done inside of the underlying logging
> > implementation?
>
> Yes, this code is doing the check twice.
>
> >
> > Is this some type of trick to improve performance?  I'm probably
> > misunderstanding it, but I just think that it adds clutter.
>
> This is an attempt to optimize the logging but I would be
> *very* surprised
> if it actually acheived any noticable performance benefits in
> most cases.
> Much Jakarta code I've seen uses the if checks on logging
> calls except in
> catch blocks.  If you're in the catch block, you've already
> incurred the
> cost of the exception mechanism so optimizing the logging doesn't make
> much sense.
>
> In my own code, I never use the if check because of the clutter.
>
> David
>
> >
> > Any insights?
> >
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >
>
>
> __________________________________
> Do you Yahoo!?
> Exclusive Video Premiere - Britney Spears
> http://launch.yahoo.com/promos/britneyspears/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [logging] logic for determing log level

Posted by David Graham <gr...@yahoo.com>.
--- __matthewHawthorne <ma...@phreaker.net> wrote:
> This is a general use question about [logging].  I'm looking through the
> 
> source for [betwixt], and I see lines like the following:
> 
> if ( log.isTraceEnabled() ) {
>    log.trace( "Is " + descriptor + " empty?" );
> }
> 
> What is the purpose of doing this check?  If trace *is* enabled, then 
> isn't the same check done inside of the underlying logging
> implementation?

Yes, this code is doing the check twice.

> 
> Is this some type of trick to improve performance?  I'm probably 
> misunderstanding it, but I just think that it adds clutter.

This is an attempt to optimize the logging but I would be *very* surprised
if it actually acheived any noticable performance benefits in most cases. 
Much Jakarta code I've seen uses the if checks on logging calls except in
catch blocks.  If you're in the catch block, you've already incurred the
cost of the exception mechanism so optimizing the logging doesn't make
much sense.

In my own code, I never use the if check because of the clutter.

David

> 
> Any insights?
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org