[slf4j-dev] [Bug 194] New: log4j-over-slf4j checks circular dependency too strict

bugzilla-daemon at pixie.qos.ch bugzilla-daemon at pixie.qos.ch
Tue Aug 10 09:50:59 CEST 2010


http://bugzilla.slf4j.org/show_bug.cgi?id=194

           Summary: log4j-over-slf4j checks circular dependency too strict
           Product: SLF4J
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: log4j-over-slf4j
        AssignedTo: slf4j-dev at qos.ch
        ReportedBy: Tom.SH.Liu at morganstanley.com


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


-- 
Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the slf4j-dev mailing list