日志框架不兼容 [英] Logging framework incompatibility

查看:28
本文介绍了日志框架不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个小型 Java 应用程序,并希望使用 logback 进行日志记录.

I'm building a small Java app and hoping to use logback for logging.

我的应用程序依赖于通过

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

...将 JCL 日志重定向到

...to redirect the JCL logging to

org.slf4j | slf4j-api | 1.6.0

...最终到

ch.qos.logback | logback-classic | 0.9.22
ch.qos.logback | logback-core | 0.9.22

所以我的应用程序可以通过其 slf4j API 通过 logback 登录,而旧的库代码可以通过重定向登录到同一位置.

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.

唉,结果是

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)

我在其中一些 jars 上尝试了更高和更低的版本号,还挖掘了 API 文档等......但我无法找到并解决问题.

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.

请帮忙?

尽管 logback 被认为是战略"日志框架,但我在最终使用的日志机制方面仍有一些余地.不过,我希望使用 logback 或 log4j,而且我绝对希望通过通用配置将旧项目的日志记录合并到新"日志记录框架最终成为的任何内容中.

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.

推荐答案

您将 jcl 桥接器的 1.5.6 版本与 slf4j-api 的 1.6.0 版本混合在一起;由于 1.6.0 中的一些更改,这将不起作用.两者使用相同的版本,即 1.6.1(最新).我一直使用 jcl-over-slf4j 桥接器,它工作正常.

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.

这篇关于日志框架不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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