What is the difference between Log4j 2 SLF4J Binding and Log4j 2 with SLF4J adapter

As a name, what is the difference between them.

And when is it better to use Log4j 2 SLF4J Binding, and when is it better to use Log4j 2 for SLF4J Adapter?

+3


source to share


1 answer


Simple really.

The log4j2-slf4j binder log4j-slf4j-impl-2.3.jar

routes calls from slf4j to log4j2.

This is the most common use case. It allows you to code your application using the slf4j API, but use log4j2 as the base implementation.



The log4j2 to slf4j adapter log4j-to-slf4j-2.3.jar

does the opposite, it routes calls from log4j2 to slf4j.

This is much less commonly used for log4j2, but even more so for older frameworks. This is useful when you have an existing application coded using the log4j2 framework but want to use a different framework. Using this adapter, you route calls from log4j2 to slf4j. slf4j can then redirect these calls to any compatible implementation, as described in the first case.

Ideally, you always want the first case as it is more straightforward and efficient. However, this may require a lot more refactoring than the second if you are working with an existing registration implementation.

+5


source







All Articles