I do think the if statements guarding code tends to help obfuscate the code.

There has been an issue suggesting a less messy way from the log4j
users perspective -
http://issues.apache.org/bugzilla/show_bug.cgi?id=16229

Doesn't work for all cases but I think it will make a lot of code
using log4j a lot cleaner. This has been marked as fixed. So is it in
a forthcoming release?

Bob.

> 
> From: Vic <[EMAIL PROTECTED]>
> Date: 2005/01/20 Thu AM 05:54:15 GMT
> To: log4j-user@logging.apache.org
> Subject: Re: Wish for CVS version: if debug enabled()
> 
> Instead of saying
> 
> if(logger.isDebugEnabled() {
>   logger.debug("XXX...
> }
> I want a method like
> 
> 
>  logger.checkDebug("XXX..
> 
> that does that.
> It looks cleaner.
> 
> .V
> 
> James Stauffer wrote:
> 
> >>Question: Right now, if debug enabled is serveral lines of code, just
> >>like in the old days.
> >>
> >>Can we place just change the signature of debug and others to indicate
> >>if the loging will only happen if enabled or all the time?
> >>This way I avoid the not nice sytnax of ... if debug enabled.
> >>    
> >>
> >
> >It already only logs if enabled.
> >
> >See the Performance section of
> >http://logging.apache.org/log4j/docs/manual.html for more info.  I
> >have included a portion to explain.
> >
> >The method invocation involves the "hidden" cost of parameter construction.
> >
> >For example, for some logger cat, writing,
> >
> >     logger.debug("Entry number: " + i + " is " + String.valueOf(entry[i]));
> >    
> >
> >incurs the cost of constructing the message parameter, i.e. converting
> >both integer i and entry[i] to a String, and concatenating
> >intermediate strings, regardless of whether the message will be logged
> >or not. This cost of parameter construction can be quite high and it
> >depends on the size of the parameters involved.
> >
> >To avoid the parameter construction cost write:
> >
> >      if(logger.isDebugEnabled() {
> >        logger.debug("Entry number: " + i + " is " + 
> > String.valueOf(entry[i]));
> >      }
> >   
> >
> >This will not incur the cost of parameter construction if debugging is
> >disabled. On the other hand, if the logger is debug-enabled, it will
> >incur twice the cost of evaluating whether the logger is enabled or
> >not: once in debugEnabled and once in debug. This is an insignificant
> >overhead because evaluating a logger takes about 1% of the time it
> >takes to actually log.
> >
> >  
> >
> 
> 
> -- 
> RiA-SoA w/JDNC <http://www.SandraSF.com> forums
> - help develop a community
> My blog <http://www.sandrasf.com/adminBlog>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

-----------------------------------------
Email provided by http://www.ntlhome.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to