[slf4j-dev] [Bug 68] java.lang.NoSuchMethodError: org.apache.log4j.Logger.isTraceEnabled()Z

bugzilla-daemon at pixie.qos.ch bugzilla-daemon at pixie.qos.ch
Fri Feb 8 17:03:19 CET 2008


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


davidr at goodserver.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |davidr at goodserver.com
             Status|RESOLVED                    |REOPENED
          Component|Unspecified                 |Implementations
         OS/Version|Windows XP                  |All
           Platform|PC                          |All
         Resolution|INVALID                     |
            Version|unspecified                 |1.4.x




------- Comment #2 from davidr at goodserver.com  2008-02-08 17:03 -------
This is a real bug, and is unavoidable in some situations. For example, when
deploying an slf4j based webapp to a jboss 4.0.5GA server, a pre-1.2.12 version
of log4j is in the bootstrap classpath, and there's nothing the webapps can do
about it. Making an isTraceEnabled method call throws an Error, and blows up
the app, breaking the facade and its contract that it will silently do nothing
if it can't log.

Having read the related threads on this subject, the correct thing to do would
be to automatically downgrade to debug logging. The code for Log4jLoggerAdapter
to handle this would be:

Constructor:

boolean traceCapableLogger = false;
try {
  logger.isTraceEnabled();
  traceCapableLogger = true;
} catch (NoSuchMethodError e) {}

public boolean isTraceEnabled() {
  if (traceCapableLogger)
    return logger.isTraceEnabled();
  else
    return logger.isDebugEnabled();
}

Then for the logging methods:

public void trace(String msg) {
  logger.log(FQCN, traceCapableLogger ? Level.TRACE : Level.DEBUG, msg, null);
}


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



More information about the slf4j-dev mailing list