2

The SLF4J documentation says that it's best practice for libraries to not include a concrete logging binding.

I'm wondering what to do about transitive dependencies though. Let's say my library A depends on another library B which depends on commons-logging. Should the pom.xml for A have an <exclude> for commons-logging or not?

If it does it would also have to include a dependency on jcl-over-slf4j because users of my library would not know that some component might use commons-logging for logging without looking at the pom.xml. Granted, this way they also have to look at the pom.xml and see slf4j in there.

The other option is to just use slf4j-api in my library A and let the end-user application Z deal with all exclusions and include all necessary bridges once.

What would be considered best practice (if there is one)?

1 Answers1

5

The SLF4J documentation says that it's best practice for libraries to not include a concrete logging binding.

Thats your answer!

Include the dependency on the logging API that you personally use. Maven will transitively bring in any logging API's from any 3rd party libraries you depend upon.

The user of your library will have two logging API's to deal with. Hence the downstream developer can choose what logging implementation they want to use and include the appropriate bridges.

To put it another way: you don't know what the final logging implementation will be so you can't bridge to it correctly.

DavidT
  • 4,601