Exception thrown while using logback/slf4j

前端 未结 8 621
忘了有多久
忘了有多久 2020-12-09 16:46

I am using slf4j 1.6.2 api jar (tried using 1.6.1 as well) - logback version is 0.9.29 (core & classic). I am using jdk1.6 on ubuntu. The exception I received is copied

相关标签:
8条回答
  • 2020-12-09 17:24

    slf4j-api version does not match that of the binding:

    An SLF4J binding designates an artifact such as slf4j-jdk14.jar or slf4j-log4j12.jar used to bind slf4j to an underlying logging framework, say, java.util.logging and respectively log4j.

    Mixing different versions of slf4j-api.jar and SLF4J binding can cause problems. For example, if you are using slf4j-api-1.7.2.jar, then you should also use slf4j-simple-1.7.2.jar, using slf4j-simple-1.5.5.jar will not work.

    NOTE From the client's perspective all versions of slf4j-api are compatible. Client code compiled with slf4j-api-N.jar will run perfectly fine with slf4j-api-M.jar for any N and M. You only need to ensure that the version of your binding matches that of the slf4j-api.jar. You do not have to worry about the version of slf4j-api.jar used by a given dependency in your project. You can always use any version of slf4j-api.jar, and as long as the version of slf4j-api.jar and its binding match, you should be fine.

    At initialization time, if SLF4J suspects that there may be a api vs. binding version mismatch problem, it will emit a warning about the suspected mismatch.

    Got from http://www.slf4j.org, I hope it can help.

    0 讨论(0)
  • 2020-12-09 17:30

    It very much looks like the version of slf4j-api.jar being loaded by the JVM has version 1.5.x. You surely have slf4j-api-1.5.x.jar on your class path (in addition to slf4j-api-1.6.2.jar). Check your class path.

    0 讨论(0)
  • 2020-12-09 17:33

    Adding the following dependencies might help :

      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
          <version>1.7.7</version>
      </dependency>
    
      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>jul-to-slf4j</artifactId>
          <version>1.7.7</version>
      </dependency>
    
      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>jcl-over-slf4j</artifactId>
          <version>1.7.7</version>
      </dependency>
    
      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>log4j-over-slf4j</artifactId>
          <version>1.7.7</version>
      </dependency>
    
      <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-jdk14</artifactId>
          <version>1.7.7</version>
      </dependency>
    
    0 讨论(0)
  • 2020-12-09 17:38

    I had the exact same error message. I solved it by excluding the dependency org.apache.directory.server:apacheds-all. Somehow that jar overrides org.slf4j.spi.LocationAwareLogger

    0 讨论(0)
  • 2020-12-09 17:39

    This may be more "me too", but I'll try to outline a more complete solution. I mix a lot of software from diverse sources together in my product. I encountered this problem first with NiFi JARs, then more recently with Cassandra JARs all over again. I had already insisted in pom.xml that I have the same version of slf4j everywhere:

    <slf4j.version>[1.7.25]</slf4j.version>
    ...
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
    ... (all the slf4j JARs I needed)
    

    Then, I told Maven I wanted Cassandra without whatever it was bringing in for slf4j:

    <dependency>
      <groupId>org.apache.cassandra</groupId>
      <artifactId>cassandra-all</artifactId>
      <version>${cassandra.version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-simple</artifactId>
        </exclusion>
    </dependency>
    

    However, like you, I was getting complaints from

    Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;
      at ch.qos.logback.classic.spi.LoggingEvent.<init>(LoggingEvent.java:112)
    

    From mvn dependency:tree, I found out that I was getting logback 1.1.3 which wasn't matching what Cassandra was apparently using (0.9-something like you). So, I excluded getting logback too by adding these exclusions to slf4j ones already there:

    <dependency>
      <groupId>org.apache.cassandra</groupId>
      <artifactId>cassandra-all</artifactId>
      <version>${cassandra.version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-simple</artifactId>
        </exclusion>
        <exclusion>
          <groupId>ch.qos.logback</groupId>
          <artifactId>logback-core</artifactId>
        </exclusion>
        <exclusion>
          <groupId>ch.qos.logback</groupId>
          <artifactId>logback-classic</artifactId>
        </exclusion>
    </dependency>
    

    ...whereupon, the problem I had and you are reporting here, went away. I hope this helps someone.

    0 讨论(0)
  • 2020-12-09 17:40

    Download from Below link

    https://jar-download.com/artifacts/ch.qos.logback/logback-classic/1.1.3/source-code

    all three jars are compatible with each other

    0 讨论(0)
提交回复
热议问题