Differences between Log4j and SLF4J

Asked

Viewed 1,447 times

6

What are the vantagens and desvantagens of each one? They can be usados simultaneamente in the same project?

1 answer

9


The advantage of SLF4J is that it is an abstraction of many of the existing log frameworks, allowing the creation of program, frameworks and libraries independent of the concrete implementation of log to be used.

This is important, for example, because the same application can be distributed (deploy) on different application servers that use different log engines. In addition, there is a serious problem when different libraries or classes used in the same project use different log mechanisms. Imagine using a MVC framework that uses java.util.logging, a persistence framework that uses Apache Commons Logging and another reporting framework that uses Log4j. The API for each of these is different and class conflicts and configuration may arise.

The SLF4J can work together with the Log4j without any difficulty, as well as being able to use other implementations.

So, if all the components of a program use the same abstraction (SLF4J, in case), then the developer or the responsible for the final environment is free to use the library of your choice, without compromising development because of a third party component.

The only context I can see where it would be advantageous to use only Log4j, would be in the case of a project without external dependencies, because there would be no reason to abstract the log mechanism.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.