On Wed, 18 Jul 2001, Justin Erenkrantz wrote:
> On Thu, Jul 19, 2001 at 12:16:27AM +0100, Pier P. Fumagalli wrote:
> > Checking out the source code, I see a lot of // (commented out lines) when
> > debug() is supposed to be called...
> > Can't we have a global constant boolean called DEBUG and replace the // with
> > if (DEBUG), so that we can simply compile in and out the debugging
> > information without touching the sources?
> >
> > Check out org.apache.catalina.connector.warp.Constants and WarpLogger... Old
> > trick we used in JServ. :)
>
> I *believe* most Java compilers do not have constant conditional
> optimizations (they certainly could, but I don't think they did last
> time I checked). Without that optimization, you must check that
> value each time you execute the statement. That might hurt. -- justin
>
>
In trivial experiments a long while back, I seem to recall that this trick
worked if your constant was "static final". But I haven't looked lately.
There are also some cases where you want to be able to set the debug level
at runtime, without having to recompile. In such cases, I typically am
real liberal about debug statements when first creating a module, and then
comment them out (versus removing them) in high-frequency-of-use portions
of the code. That way, you've got ready-made debug code to uncomment if
you run into problems later.
Craig