3

I have a strange double error with SLF4J.

I'm trying to get SLF4J to bind to Log4J.

In Eclipse, when I run a Maven Clean and then a Maven Install, I get this in the Maven Install output:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Later on, when running the jUnit tests for the project, one of the tests calls a method that logs a message (I haven't cleaned it up to not log yet).
But instead of logging, I get this message:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/JDunn/.m2/repository/ch/qos/logback/logback-classic/0.9.30/logback-classic-0.9.30.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/JDunn/.m2/repository/org/slf4j/slf4j-log4j13/1.0.1/slf4j-log4j13-1.0.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

So it seems that SLF4J first can't load a Binder, and then it finds multiple Bindings!

In my pom.xml, I have only one relevant dependency:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j13</artifactId>
    <version>1.0.1</version>
</dependency>

To resolve the issue, I tried deleting the first binding from my repository, namely this one:

C:/Users/JDunn/.m2/repository/ch/qos/logback/logback-classic/0.9.30/logback-classic-0.9.30.jar

I ran another Maven Clean, Maven Install and got a strange error when it tried to run the tests:

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.14:test (default-test) on project sonar-score-plugin: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.14:test failed: There was an error in the forked process

I then ran Maven Clean, Maven Install again, and got the original "Multiple Bindings" error again, and found that the directory I had deleted was there again as if I hadn't deleted it.

I don't know what else I can do to get rid of the "Multiple Bindings" error.

Note: I found a similar question, but I don't have the same cause that could be effecting this error.

Also, the "No Binder Found" error at the top might be because of this, though I'm not sure.

Community
  • 1
  • 1
James Dunn
  • 8,064
  • 13
  • 53
  • 87

2 Answers2

1

It turns out that another dependency (We'll call it Dependency A) in my project has, among its own dependencies, a dependency on ch.qos.logback:logback-classic. Adding exclusions for this dependency to Dependency A resulted in errors, so I decided to ditch trying to bind to log4j and just let it bind to logback-classic.

I removed the dependency:

slf4j-log4j13

I then replaced it with:

slf4j-api

This removed the multiple-bindings error.

I'm assuming the top error message of no bindings is due to the fact that it is given before the dependencies of dependencies are downloaded. So I'm going to ignore it as my code works just fine.

James Dunn
  • 8,064
  • 13
  • 53
  • 87
0

It seems to me that you have multiple bindings in your test dependencies (either explicit, or implicit as dependencies of dependencies).

Your "normal" (non-test) dependencies do not have the same issue - the don't in fact include a single SFL4j binding.

Note that, not being a user of either Maven or Eclipse, I have no idea how to solve the problem. I'm just pointing out what looks like the root of the issue, hoping that a) I'm right and b) that'll be enough for you to work the rest out.

Nicolas Rinaudo
  • 6,068
  • 28
  • 41