Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2315

LevelRangeFilter min and max values are behaving opposit

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.10.0
    • None
    • Filters
    • None

    Description

      LevelRangeFilter's minLevel and maxLevel are behaving opposite then it's previous (log4j 1.2.X) versions. 

      For example, if you set minLevel=DEBUG and maxLevel=INFO, I would expect both DEBUG and INFO logs should be in the targeted output and all the other levels should be filtered. That's how it used to work in log4j 1.2.x version). 

      However, in log4j2, it doesn't really output anything (i.e. it filters out all the levels). If you swap the value of minLevel and maxLevel then (i.e. minLevel=INFO and maxLevel=DEBUG),  it works as expected. This is very confusing. 

      Looking at the documentation and code, I think this is happening due to following:

      1. In Log4j 1.x, the priority value of levels were in ascending order. It means INFO will have higher value than DEBUG.  However, in  log4j2.x, the concept is different. There is an associated intValue with each level and according to documentation, intValues are in descending order. it means DEBUG's intValue (500) is higher than INFO's (400).
      2. With this change of priority/intValues from ascending to descending, following logic in Level.java never returns true for a minLevel=DEBUG and maxLevel=INFO in Log4j2. 

      public boolean isInRange(final Level minLevel, final Level maxLevel) {
      return this.intLevel >= minLevel.intLevel && this.intLevel <= maxLevel.intLevel;
      }

      I think this needs to be corrected as the meaning of minLevel and maxLevel are very intuitive and current implement is totally opposite of it and makes it very confusing. 

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            jignesh.shukla@gmail.com JIGNESH S SHUKLA
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: