How to find which library slf4j has bound itself t

2019-02-01 05:10发布

I am using slf4j for logging in my application. I get the purpose of slf4j. I would like to know how to find out which logging-library slf4j is currently binding to. I have log4j in my referenced libraries. I am assuming that slf4j has bound itself to log4j.

What I would like to know is, is there any way to explicitly confirm this binding?

3条回答
我只想做你的唯一
2楼-- · 2019-02-01 05:33

Just do what SLF4J does to discover the binding:

final StaticLoggerBinder binder = StaticLoggerBinder.getSingleton();

Now you can try to find out what is the actual implementation in my case:

System.out.println(binder.getLoggerFactory());
System.out.println(binder.getLoggerFactoryClassStr());

This prints:

ch.qos.logback.classic.LoggerContext[default]
ch.qos.logback.classic.selector.DefaultContextSelector
查看更多
Root(大扎)
3楼-- · 2019-02-01 05:39

The StaticLoggerBinder's getLoggerFactoryClassStr() method is probably what you're looking for.

查看更多
贪生不怕死
4楼-- · 2019-02-01 05:42

Easy. Put a breakpoint on .. say.. LOG.info(...). Once debugger stops there, step into.. and viola.. you will find yourself in the code of the actual logger... say log4j or logback.. whatever.

查看更多
登录 后发表回答