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 ;) -- Cheers, Pete *------------------------------------------------------* | Despite your efforts to be a romantic hero, you will | | gradually evolve into a postmodern plot device. | *------------------------------------------------------* --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]