Java 日志框架不兼容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3519978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Logging framework incompatibility
提问by Carl Smotricz
I'm building a small Java app and hoping to use logback for logging.
我正在构建一个小型 Java 应用程序并希望使用 logback 进行日志记录。
My app has a dependency on an older project that does its logging via
我的应用程序依赖于通过以下方式进行日志记录的旧项目
org.apache.commons | com.springsource.org.apache.commons.logging | 1.1.1
...so my plan was to use
...所以我的计划是使用
org.slf4j | jcl-over-slf4j | 1.5.6
...to redirect the JCL logging to
...将 JCL 日志重定向到
org.slf4j | slf4j-api | 1.6.0
...and ultimately to
...并最终
ch.qos.logback | logback-classic | 0.9.22
ch.qos.logback | logback-core | 0.9.22
so my app can log through logback via its slf4j API while the old library code can log into the same location via the redirection.
所以我的应用程序可以通过其 slf4j API 通过 logback 登录,而旧的库代码可以通过重定向登录到同一位置。
Alas, this results in
唉,这导致
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.info(SLF4JLocationAwareLog.java:141)
I've tried higher and lower verision numbers on some of these jars and also digging through API documentation and such... but I'm unable to find and solve the problem.
我已经在其中一些 jars 上尝试了更高和更低的版本号,并且还挖掘了 API 文档等等......但我无法找到并解决问题。
Help, please?
请帮忙?
Although logback is considered the "strategic" logging framework, I have some leeway in which logging mechanism I ultimately use. I'd hope to use either logback or log4j, though, and I definitely want to merge the old project's logging into whatever the "new" logging framework ends up being, via a common configuration.
尽管 logback 被认为是“战略”日志框架,但我对最终使用的日志机制仍有一些余地。不过,我希望使用 logback 或 log4j,并且我绝对希望通过通用配置将旧项目的日志记录合并到“新”日志记录框架最终成为的任何内容中。
采纳答案by Holger Hoffst?tte
You are mixing the 1.5.6 version of the jcl bridge with the 1.6.0 version of the slf4j-api; this won't work because of a few changes in 1.6.0. Use the same versions for both, i.e. 1.6.1 (the latest). I use the jcl-over-slf4j bridge all the time and it works fine.
您将 jcl 桥的 1.5.6 版本与 slf4j-api 的 1.6.0 版本混合在一起;由于 1.6.0 中的一些更改,这将不起作用。两者使用相同的版本,即 1.6.1(最新)。我一直在使用 jcl-over-slf4j 桥,它工作正常。
回答by Peter L
Just to help those in a similar situation to myself...
只是为了帮助那些和我有类似情况的人......
This can be caused when a dependent library has accidentally bundled an old version of slf4j. In my case, it was tika-0.8. See https://issues.apache.org/jira/browse/TIKA-556
当依赖库意外捆绑了旧版本的 slf4j 时,可能会导致这种情况。就我而言,它是 tika-0.8。见https://issues.apache.org/jira/browse/TIKA-556
The work around is exclude the component and then manually depend on the correct or patched version.
解决方法是排除组件,然后手动依赖正确或修补的版本。
EG.
例如。
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>0.8</version>
<exclusions>
<exclusion>
<!-- NOTE: Version 4.2 has bundled slf4j -->
<groupId>edu.ucar</groupId>
<artifactId>netcdf</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<!-- Patched version 4.2-min does not bundle slf4j -->
<groupId>edu.ucar</groupId>
<artifactId>netcdf</artifactId>
<version>4.2-min</version>
</dependency>
回答by linuxbuild
SLF4J 1.5.11 and 1.6.0 versions are not compatible (see compatibility report) because the argument list of org.slf4j.spi.LocationAwareLogger.log
method has been changed (added Object[] p5):
SLF4J 1.5.11 和 1.6.0 版本不兼容(参见兼容性报告),因为org.slf4j.spi.LocationAwareLogger.log
方法的参数列表已更改(添加了 Object[] p5):
SLF4J 1.5.11:
SLF4J 1.5.11:
LocationAwareLogger.log ( org.slf4j.Marker p1, String p2, int p3,
String p4, Throwable p5 )
SLF4J 1.6.0:
SLF4J 1.6.0:
LocationAwareLogger.log ( org.slf4j.Marker p1, String p2, int p3,
String p4, Object[] p5, Throwable p6 )
See compatibility reports for other SLF4J versions on this page.
请参阅此页面上其他 SLF4J 版本的兼容性报告。
You can generate such reports by the japi-compliance-checkertool.
您可以通过japi-compliance-checker工具生成此类报告。