asanso / openid4java

Automatically exported from code.google.com/p/openid4java
Apache License 2.0
0 stars 0 forks source link

Don't store logging-enabled result in static final variable #164

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The enablement of the debug logger is stored in static final variable in most 
classes, which makes it impossible to enable or disable logging at runtime, 
which is a feature of log4j system we use (maybe others as well). In log4j, the 
isDebugEnabled is designed to be very cheap operation specially for this 
purpose.

I suggest to remove the statement

  private static final boolean DEBUG = _log.isDebugEnabled();

and to call "_log.isDebugEnabled()" every time the constant was used.

Original issue reported on code.google.com by viliam.d...@gmail.com on 21 Sep 2011 at 5:58

GoogleCodeExporter commented 8 years ago
I agree with you.

Original comment by zhoushu...@gmail.com on 21 Sep 2011 at 6:04

GoogleCodeExporter commented 8 years ago
Here is a patch...
Searched for "DEBUG", if the variable is named otherwise somewhere, this is not 
refactored.

Original comment by viliam.d...@gmail.com on 22 Sep 2011 at 6:14

GoogleCodeExporter commented 8 years ago
Here is a revised patch: I added some micro-optimization, that the test for 
"isDebugEnabled" is not necessary, if there is not any processing before the 
call to _log.debug is made, e.g. only a string constant is there. The test 
takes place at the very beginning of the _log.debug method.

Original comment by viliam.d...@gmail.com on 22 Sep 2011 at 6:39

Attachments:

GoogleCodeExporter commented 8 years ago
Debug level is not set at compile-time -- it can definitely be set at runtime, 
just need to restart the application; isDebugEnabled() may not be as 
efficiently implemented with all loggers as is with log4j.

Original comment by Johnny.B...@gmail.com on 1 Nov 2012 at 2:21