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.
The log4j’s
AppenderandCategoryclasses 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
Categoryclass 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.xmlorlog4j.propertiesthelog4j-over-slf4jmodule will work fine because the application does not use the configuration methods of theAppenderand 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.