I believe this is not possible (unless you are doing something extremely cumbersome, like a container that creates a child class loader for your application ... something like that)
The main idea of ββSLF4j to have a replaceable implementation is to have a middleware lib that provides org.slf4j.impl.StaticLoggerBinder , and the SLF4J API will look for this class through the class loader. Therefore, if there is more than 1 binder in the classpath, there is no way to distinguish the org.slf4j.impl.StaticLoggerBinder that they provide. The DI Framework is not going to help with this, given that the Logging environment is initialized before the DI happens.
If the SLF4J does not change its design in the future, we will not be able to do much. And, I doubt that even the SLF4J is changing its design. Since we cannot tell the DI container that Logging initialization is what it all depends on. I believe that there are more reasons to make it almost impossible.
However, that I doubt whether this is really related to DI? Honestly, I don't see a problem with controlling which logging binding is used by putting the appropriate JAR in the classpath. If you want to control it at runtime, as programmatically, I think writing a small container to launch your application is the way to go. However, this is not related to DI.
source share