简体   繁体   中英

How to handle multiple bindings for SLF4j

In my project, I use slf4j and logback as the backend logging framework.But there are a lot of dependencies which use log4j as the logging framework.So it turns out there are multiple bindings of slf4j.How can I handle that? If I exclude the unwanted slf4j-log4j dependencies,will the framework or library themselves handle the logging correctly?

You can safely exclude other bindings. slf4j will bind other libraries with logback.

So long as there is just one binding on the path, SLF4J will make sure all logging happening against it will end up in that logging implementation.

If your dependencies bring different bindings or logging implementations with them, it gets a little more complicated. But SLF4J provides bridges for this very situation:

http://www.slf4j.org/legacy.html

So the preferred way would be to have dependencies for SLF4J and logback and excluding every other logging framework while adding the bridge for it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM