如何燮有关的多个绑定preSS SLF4J警告? [英] How to suppress SLF4J Warning about multiple bindings?

查看:222
本文介绍了如何燮有关的多个绑定preSS SLF4J警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Java项目有不同的版本SLF4J依赖。我如何燮preSS恼人的警告?

My java project has dependencies with different SLF4J versions. How do I suppress the annoying warnings?

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:xyz234/lib/slf4j-
log4j12-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:xyz123/.m2/repository/org/slf4j/slf4j-log4j12
/1.6.0/slf4j-log4j12-1.6.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

P.S:这不是同样的问题<一href=\"http://stackoverflow.com/questions/6418147/slf4j-warning-about-the-same-binding-being-duplicate\">slf4j警告差不多的结合存在重复,答案还有就是如何摆脱假警报警告的,在我的情况下,它不过是一个真正的警告。
P.S.S:对不起,我忘了提:我使用Maven和SLF4J包括在我的依赖关系的依赖

P.S.: This is not the same question as slf4j warning about the same binding being duplicate, the answer there is how to get rid of a false alarm warning, in my case it is a true warning however. P.S.S.: Sorry, I forgot to mention: I use Maven and SLF4J is included in the dependencies of my dependencies.

推荐答案

删除之一 SLF4J-log4j12-1.5.8.jar SLF4J-log4j12-1.6.0.jar 从classpath。您的项目不应该依赖于不同版本的SLF4J。我建议你​​只使用1.6.0。

Remove one of the slf4j-log4j12-1.5.8.jar or slf4j-log4j12-1.6.0.jar from the classpath. Your project should not depend on different versions of SLF4J. I suggest you to use just the 1.6.0.

如果您使用的是Maven,您可以排除传递依赖的。下面是一个例子:

If you're using Maven, you can exclude transitive dependencies. Here is an example:

<dependency>
    <groupId>com.sun.xml.stream</groupId>
    <artifactId>sjsxp</artifactId>
    <version>1.0.1</version>
    <exclusions>
        <exclusion>
            <groupId>javax.xml.stream</groupId>
            <artifactId>stax-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>

随着当前SLF4J-API实现它不是可能消除这些警告。在 org.slf4j.LoggerFactory 类打印消息:

With the current slf4j-api implementation it is not possible to remove these warnings. The org.slf4j.LoggerFactory class prints the messages:

  ...
  if (implementationSet.size() > 1) {
    Util.report("Class path contains multiple SLF4J bindings.");
    Iterator iterator = implementationSet.iterator();
    while(iterator.hasNext()) {
      URL path = (URL) iterator.next();
      Util.report("Found binding in [" + path + "]");
    }
    Util.report("See " + MULTIPLE_BINDINGS_URL + " for an explanation.");
  }
  ...

的Util 类是以下内容:

public class Util {

  static final public void report(String msg, Throwable t) {
    System.err.println(msg);
    System.err.println("Reported exception:");
    t.printStackTrace();
  }
  ...

报告方法直接写入 System.err的。一种解决方法可能是更换 System.err的<$c$c>System.setErr()之前的 的第一 LoggerFactory.getLogger()呼叫,但如果你这样做,你可能会失去其他重要信息。

The report method writes directly to System.err. A workaround could be to replace the System.err with System.setErr() before the first LoggerFactory.getLogger() call but you could lose other important messages if you do that.

当然,你可以下载源代码并删除这些 Util.report 通话,并使用修改后的SLF4J的API,在您的项目。

Of course you can download the source and remove these Util.report calls and use your modified slf4j-api in your project.

这篇关于如何燮有关的多个绑定preSS SLF4J警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆