[slf4j-user] SLF4J incorrectly determines that Class path contains multiple SLF4J bindings

Ari Meyer ari.meyer at gmail.com
Thu Jul 23 05:52:12 CEST 2009


Hi,

I get this warning in my Eclipse console (using WTP to connect to 
WebLogic 10.3):

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [zip:C:/Documents and 
Settings/Owner.ZEN/.m2/repository/org/slf4j/slf4j-log4j12/1.5.8/slf4j-log4j12-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [zip:C:/Documents and 
Settings/Owner.ZEN/.m2/repository/org/slf4j/slf4j-log4j12/1.5.8/slf4j-log4j12-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an 
explanation.

Somehow, it's seeing multiple bindings, when they are in fact the same.  
I'm not sure how this is happening (I use Maven and the 
maven-eclipse-plugin for configuration).  Referencing this code from 
LoggerFactory:

  private static String STATIC_LOGGER_BINDER_PATH = 
"org/slf4j/impl/StaticLoggerBinder.class";

  private static void singleImplementationSanityCheck() {
    try {
      Enumeration paths = LoggerFactory.class.getClassLoader().getResources(
          STATIC_LOGGER_BINDER_PATH);
      List implementationList = new ArrayList();
      while (paths.hasMoreElements()) {
        URL path = (URL) paths.nextElement();
        implementationList.add(path);
      }
      if (implementationList.size() > 1) {
        Util
            .reportFailure("Class path contains multiple SLF4J bindings.");
        for(int i = 0; i < implementationList.size(); i++) {
          Util.reportFailure("Found binding in 
["+implementationList.get(i)+"]");
        }
        Util.reportFailure("See " + MULTIPLE_BINDINGS_URL
            + " for an explanation.");
      }
    } catch (IOException ioe) {
      Util.reportFailure("Error getting resources from path", ioe);
    }
  }

... somehow, the Enumeration "paths" must have 2 elements that happen to 
be identical -- probably due to my multiple WAR within EAR config (if I 
shared my utility JAR at the EAR level, this probably won't show up).

Simple fix: change implementationList from List to Set -- this way there 
will be no duplicates.

Best regards,
Ari




More information about the slf4j-user mailing list