开发者

SLF4J log4j NoSuchMethodError on Category

开发者 https://www.devze.com 2023-03-27 16:28 出处:网络
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:

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 appender开发者_JAVA技巧s 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.


The log4j's Appender and Category classes contain some methods (for example Category.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 no getRoot() method. I don't think that any property or xml file would change it. From http://www.slf4j.org/legacy.html#log4j-over-slf4j:

However, when log4j is configured through a configuration file, be it log4j.properties or log4j.xml, the log4j-over-slf4j module should just work fine.

It just means that if your application's logging is configured only with log4j.xml or log4j.properties the log4j-over-slf4j module will work fine because the application does not use the configuration methods of the Appender 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消