Question:
What are the vantagens
and desvantagens
of each? Can they be usados simultaneamente
in the same project?
Answer:
The advantage of SLF4J
is that it is an abstraction of many of the existing log frameworks, allowing the creation of programs, frameworks and libraries independent of the concrete log implementation to be used.
This is important, for example, because the same application can be distributed ( deploy ) to different application servers that use different logging mechanisms. Furthermore, there is a serious problem when different libraries or classes used in the same project use different logging mechanisms. Imagine using an 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 and configuration conflicts can arise.
SLF4J
can work together with Log4j
without any difficulty, and it can also use other implementations.
So, if all components of a program use the same abstraction ( SLF4J
, in this case), then the developer or the person responsible for the final environment is free to use the library of their 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 with no external dependencies, as there would be no reason to abstract the logging mechanism.