Peter Donald wrote:
> 
> On Fri, 26 Oct 2001 06:29, Stefano Mazzocchi wrote:
> > There are two solutions:
> >
> > 1) compile-time
> >
> >     public final static boolean DEBUG = false;
> >
> >     if (DEBUG) getLogger().debug(...);
> >
> > where almost all java compiler are able to optimize the code by entirely
> > removing the line since there the final behavior of the variable make it
> > possible to know the future of this call (never called, that is).
> >
> > 2) run-time
> >
> >     Logger logger = getLogger();
> >     if (logger.debugOn()) logger.debug(...);
> >
> > which is, admittedly, makes the code less readable but, hey, it's much
> > better than loosing 30% performance for having placed debug logging code
> > (now disabled) for nothing.
> >
> > IMO, the Avalon LogKit should force (or at least *highly* incouradge)
> > people to use this approach.
> 
> (1) is useful in the 1.2 JVMs because they don't optimize aswell as 1.3+. (2)
> will still cause 5-8 operations/comparisons before opting out in jdk1.2 but
> in later JVMs this will be optimized down to one comparison and a jump.
> 
> I am not sure how it can be "forced" other than via recomendation ;)

Good point.

A possible solution is to require the logging channel instance to be
obtained only after checking if available... we can use some polymorphic
code like

 LogChannel debug = (LogChannel) getLogger().debug();
 if (debug != null) debug.log(...);

which is sort of inverted over the normal use but rightly forces the
logging code to obtain a reference to the log channel *before* doing
anything (pain NPE all over the place!).

Not sure I like this much, but it's a way to do it.

What do you think?

-- 
Stefano Mazzocchi      One must still have chaos in oneself to be
                          able to give birth to a dancing star.
<[EMAIL PROTECTED]>                             Friedrich Nietzsche
--------------------------------------------------------------------



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

Reply via email to