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

Log4j 1.2 Bridge doesn't map level ALL correctly in Category.getEffectiveLevel()

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.1
    • 2.2
    • Log4j 1.2 bridge
    • None

    Description

      If I have in my logger configs:

      <logger name="org.hibernate" level="ALL"/>
      

      Using "ALL" as my log level for hibernate. Hibernate uses jboss-logging. Jboss-logging just recently added support for Log4j2 (see version 3.2 - https://issues.jboss.org/browse/JBLOGGING-95). However, I'm using 3.1.4 currently which ends up then using the log4j 1.2 bridge so:

      jboss-logging 3.1.4--->log4j 1.2 bridge--->log4j2
      

      I noticed some Hibernate code failing checking the logger level such as:

      if (logger.isTraceEnabled() { 
          // log something expensive
      }
      

      Looking into this, it checks the loggers effective level against the passed in level. So in this case the loggers effective level should be ALL which should include TRACE. However, in the log4 1.2 bridge Category.getEffectiveLevel() doesn't have a case statement for ALL so it ends up defaulting to OFF:

      public final Level getEffectiveLevel() {
              switch (logger.getLevel().getStandardLevel()) {
                  case TRACE:
                      return Level.TRACE;
                  case DEBUG:
                      return Level.DEBUG;
                  case INFO:
                      return Level.INFO;
                  case WARN:
                      return Level.WARN;
                  case ERROR:
                      return Level.ERROR;
                  case FATAL:
                      return Level.FATAL;
                  default:
                      return Level.OFF;
              }
          }
      

      Here's the JBoss logging check for reference - https://github.com/jboss-logging/jboss-logging/blob/master/src/main/java/org/jboss/logging/Log4jLogger.java#L36

      The first conditional will be true but the second will be false due to the issue of mapping the ALL level.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            rrupp Ryan Rupp
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment