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:
It is both hacky and ingenious – you are removing
log4j.jarand replacing it withlog4j-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.