Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use Log4j.xml configuration for SLF4J and Logback?

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?

like image 489
Mavlarn Avatar asked Dec 22 '11 09:12

Mavlarn


People also ask

Can I use both log4j and 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 ?

Does SLF4J use log4j or Logback?

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.

Can we use log4j and SLF4J together?

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.

Is Logback and SLF4J same?

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.


2 Answers

If you change the logger implementation to logback, you should use a logback.xml config file (and its associated format).

like image 54
Jean-Philippe Briend Avatar answered Sep 30 '22 02:09

Jean-Philippe Briend


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.

like image 26
Ceki Avatar answered Sep 30 '22 04:09

Ceki