Hi,
so I did the switch on my local checkout and after
a little fiddling I'm the happy owner of a GeoServer
whose logging levels can be modified on the fly,
and correctly too. Moreover, the code needed to
configure logging has been drastically simplified (it's
maybe 1/10th of what it used to be), since all I need
to do now is to have log4j reload it configuration
(instead of trying to force every java logger to
change its logging level and whatnot).

To make this work smoothly I had to do a couple
of modifications on the log4j log level mapping, turning
it into:

     /**
      * Returns the Log4J level for the given Java level.
      */
     private static org.apache.log4j.Level toLog4JLevel(final Level level) {
         final int n = level.intValue();
         switch (n / 100) {
             default: {
                 // MAX_VALUE is a special value for Level.OFF. 
Otherwise and
                 // if positive, log to fatal since we are greater than 
SEVERE.
                 switch (n) {
                     default: if (n >= 0)    return 
org.apache.log4j.Level.FATAL; // fallthrough otherwise.
                     case Integer.MAX_VALUE: return 
org.apache.log4j.Level.OFF;
                     case Integer.MIN_VALUE: return 
org.apache.log4j.Level.ALL;
                 }
             }
             case 10: return org.apache.log4j.Level.ERROR;    // SEVERE
             case  9: return org.apache.log4j.Level.WARN;     // WARNING
             case  8:                                         // INFO
             case  7: return org.apache.log4j.Level.INFO;     // CONFIG
             case  6:                                         // (not 
allocated)
             case  5: return org.apache.log4j.Level.DEBUG;    // FINE
             case  4: return org.apache.log4j.Level.TRACE;    // FINER
             case  3:                                         // FINEST
             case  2:                                         // (not 
allocated)
             case  1:                                         // (not 
allocated)
             case  0: return org.apache.log4j.Level.ALL;      // ALL
         }
     }

The changes are:
* moved TRACE to finer level. This is because many geotools modules
   don't ever go lower than FINER and they log a huge number of
   messages at the FINER level (renderer and shapefile renderer do
   so, making the FINER level usage almost impractical unless a well
   hidden rendering issue is to be spotted)
* used ALL for the lastest level, not OFF. OFF is meant to be
   the highest level, the one at no-one should be logging anything.
* the opposite method, toJavaLevel, has been changed accordingly.

What do you think, can I go forward and commit? What about the commons
logger, I think I should make the same change there?

Cheers
Andrea

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to