I have a project using common-logging
and log4j
, I want to change to use SLF4J + Logback. Is there any way to use existing log4j.xml
for Logback?
As the slf4j documentation says, you just have to replace all the log4j dependencies with a single one from slf4j, named log4j-over-slf4j: http://slf4j.org/legacy.html#log4j-over-slf4j. Any code that is under your direct control can just use slf4j + logback as it always would. Thus we use following scheme ?
Simple Logging Facade for Java (abbreviated SLF4J) acts as a facade for different logging frameworks (e.g., java. util. logging, logback, Log4j). It offers a generic API, making the logging independent of the actual implementation.
So essentially, SLF4J does not replace log4j; they both work together. It removes the dependency on log4j from your application and makes it easy to replace it in the future with the more capable library.
Logback and SLF4J can be primarily classified as "Log Management" tools. According to the StackShare community, Logback has a broader approval, being mentioned in 4 company stacks & 9 developers stacks; compared to SLF4J, which is listed in 5 company stacks and 7 developer stacks.
If you change the logger implementation to logback, you should use a logback.xml config file (and its associated format).
There exists a log4j.properties to logback.xml migrator available online: http://logback.qos.ch/translator/
For log4j.xml files, there structure of logback.xml files is very similar. Thus, it should not be hard to migrate your log4j.xml to logback.xml manually. If you run into trouble please post on the logback-user mailing list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With