Bug 37119 - Space after log level causes default level to be used
Space after log level causes default level to be used
Status: RESOLVED FIXED
Product: Log4j
Classification: Unclassified
Component: Appender
unspecified
All other
: P4 normal
: ---
Assigned To: log4j-dev
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2005-10-17 15:45 UTC by Colum Sisk
Modified: 2006-08-31 13:42 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Colum Sisk 2005-10-17 15:45:49 UTC
For the rootCategory definitions, whitespace characters between the log level 
and the comma before log type causes the default log level to be used (DEBUG)

  >  log4j.rootCategory=INFO , FILE

For the above rootCategory definition, the logger uses DEBUG as default for the 
log level. This is because the method "public static Level toLevel(String sArg, 
Level defaultLevel)" in the org.apache.log4j.Level class does not trim the level 
string. 

Therefore from the above definition of rootCatetory the string "INFO " is passed 
to the toLevel method. Which does not match any of the criteria in the toLevel 
method. A simple trim of the whitespace in the toLevel method would solve this 
issue. 



  /**
     Convert the string passed as argument to a level. If the
     conversion fails, then this method returns the value of
     <code>defaultLevel</code>.  
  */
  public
  static
  Level toLevel(String sArg, Level defaultLevel) {                  
    if(sArg == null)
       return defaultLevel;
    
    String s = sArg.toUpperCase();

    if(s.equals("ALL")) return Level.ALL; 
    if(s.equals("DEBUG")) return Level.DEBUG; 
    if(s.equals("INFO"))  return Level.INFO;
    if(s.equals("WARN"))  return Level.WARN;  
    if(s.equals("ERROR")) return Level.ERROR;
    if(s.equals("FATAL")) return Level.FATAL;
    if(s.equals("OFF")) return Level.OFF;
    if(s.equals("TRACE")) return Level.TRACE;
    return defaultLevel;
  }
Comment 1 Scott Deboy 2005-10-17 16:27:56 UTC
Now that we support TRACE, we should also decide if we should change the default
(fallback) level to TRACE.
Comment 2 Curt Arnold 2006-08-31 20:42:21 UTC
Added a String.trim() in the implementation of OptionConverter.toLevel() which should address the issue 
in PropertyConfigurators.  Whether TRACE should be used as default if level is unrecognized is a distinct 
issue.  I think it should stick the way that it is, but if you disagree, log a new bug request.

Committed in rev 439043 and 439044 (trunk and 1.2 branch, respectively).