If a 3rd party dependency logs using a concrete framework (such as log4j), and I want my app to do all logging via slf4j, then is it possible to configure log4j (either in XML, properties file, etc.) to redirect the log messages to the slf4j API? (Which, at runtime, would bind to a concrete slf4j binding of my choice.)
It would just be nice to get all log messages going to the same place through the same API.
I don't even mind if I have to do something a little crazy, like point log4j.properties to some interim code (that I would write), which in turn directs traffic to slf4j!
I just don't know where to start. Thanks in advance!
Of course you can and it is thoroughly explained in the documentation:
log4j-over-slf4j
SLF4J ship with a module called
log4j-over-slf4j
. It allows log4j users to migrate existing applications to SLF4J without changing a single line of code but simply by replacing the log4j.jar file withlog4j-over-slf4j.jar
, as described below.
It is both hacky and ingenious - you are removing log4j.jar
and replacing it with log4j-over-slf4j.jar
. The latter JAR mirrors Log4J classes in the same packages, so your application and libraries don't even have to be recompiled. But the new implementations are simply rerouting to SLF4J.
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