Uploaded image for project: 'SLF4J'
  1. SLF4J
  2. SLF4J-185

log4j-over-slf4j checks circular dependency too strict

    Details

    • Type: Bug
    • Status: Closed
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: 1.7.14
    • Component/s: log4j-over-slf4j
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

      Description

      Hi guys,

      I think log4j-over-slf4j (as well as jcl bridges) checks circular dependency too strict.
      Even when slf4j-log4j12.jar is visible, it does not necessarily mean it will be picked up by slf4j-api as the logging backend.

      Here is a setup in tomcat 6 demonstrate the issue:
      tomcat container lib contains: jcl-over-slf4j.jar, slf4j-api.jar, slf4j-log4j12.jar, log4j.jar
      Webapp WEB-INF/lib contains: log4j.jar, log4j-over-slf4j.jar, slf4j-api.jar, logback-core.jar, logback-access.jar.
      What we want to achieve is that tomcat logging (from commons-logging) will be routed to log4j and webapp's logging (from log4j) will be routed to logback.
      In theory, there will be no circular dependencies in runtime as logback is picked up as the logging backend. However, webapp failed to start because the "potential" circular dependency is detected.

      Is it possible to change the circular dependency detection algorithm to test against the actual binding picked up? I did a hack on org.apache.log4j.Log4jLoggerFactory which works for me:
      class Log4jLoggerFactory {
      ...

      static {

      LoggerFactoryBinder binder = StaticLoggerBinder.getSingleton();
      if ("org.slf4j.impl.Log4jLoggerFactory".equals(binder.getLoggerFactoryClassStr()))

      { String part1 = "Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError. REPLACED "; String part2 = "See also " + LOG4J_DELEGATION_LOOP_URL + " for more details."; Util.reportFailure(part1); Util.reportFailure(part2); throw new IllegalStateException(part1 + part2); }

      }
      ...

      }

      Thanks,
      Tom

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                slf4j-dev SLF4J developers list
                Reporter:
                tomliliu tomliliu
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: