类别上的 SLF4J log4j NoSuchMethodError
我使用 SLF4J + LogBack 来处理日志记录,并使用适当的 jar 来路由其他日志记录框架调用。但是我遇到了这里提到的问题: http://www.slf4j.org/legacy.html#log4j-over- slf4j
我在调用 Appender
时收到 NoSuchMethodError
(具体来说Category.getRoot()
)。
它提到使用 log4j.properties
或 log4j.xml
文件应该可以解决这些问题,但我不太确定该配置文件会是什么样子(哪些附加程序和要使用的类别),或者放置它的位置(与 logback.xml 相同的位置?)
我也看到过: 用 LogBack、log4j-over-slf4j 替换 Log4j 的问题。 jar 缺点
这似乎本质上是同一个问题,但从未真正得到解答。
I'm using SLF4J + LogBack to handle my logging, and have the appropriate jars to route the other logging framework calls. However I've run across the issue noted here:
http://www.slf4j.org/legacy.html#log4j-over-slf4j
Where in I'm getting a NoSuchMethodError
on the call of an Appender
(specifically Category.getRoot()
).
It mentions that using a log4j.properties
or log4j.xml
file should fix these issues, but I'm not exactly sure what that config file would look like (which appenders and categories to use), or where to place it (same location as the logback.xml?)
I've also seen this:
Issues replacing Log4j with LogBack, log4j-over-slf4j.jar shortcomings
Which seems to be essentially the same question, but never really answered.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
log4j 的
Appender
和Category
类包含一些可以更改日志记录配置的方法(例如Category.addAppender()
)。由于 slf4j 只是一个简单的日志记录外观,其配置完全依赖于底层日志框架(logback、log4j、java-util-logging 等),因此 slf4j 不支持这些方法。检查 log4j-over-slf4j模块的
Category
类的源代码,没有getRoot()
方法。我不认为任何属性或 xml 文件会改变它。来自 http://www.slf4j.org/legacy.html#log4j-over- slf4j:这只是意味着,如果您的应用程序的日志记录仅使用
log4j.xml
或log4j.properties
配置,则log4j-over-slf4j
模块将正常工作因为应用程序不使用 Appender 和 Category(可能还有其他)类的配置方法。它仅使用 log4j 进行日志记录,而不是对其进行配置,并且所需的记录器方法存在于 log4j-over-slf4j 模块中。因此,如果您的应用程序使用配置方法,您必须修改代码。The log4j's
Appender
andCategory
classes contain some methods (for exampleCategory.addAppender()
) which can change the logging configuration. Since slf4j just a simple facade for logging, the configuration fully depends on the underlying logging framework (logback, log4j, java-util-logging etc.), so slf4j does not support these methods.Check the source code of the
Category
class of the log4j-over-slf4j module, there is nogetRoot()
method. I don't think that any property or xml file would change it. From http://www.slf4j.org/legacy.html#log4j-over-slf4j:It just means that if your application's logging is configured only with
log4j.xml
orlog4j.properties
thelog4j-over-slf4j
module will work fine because the application does not use the configuration methods of theAppender
and Category (and maybe other) classes. It uses log4j just for logging, not to configure it and the required logger methods exist in the log4j-over-slf4j module. So, if your application uses the configuration methods you have to modify the code.