Let's say we build a Java SDK and different projects can consume by adding it as a jar in the classpath or adding it as a dependency in the maven pom.xml or gradle file. Logs from the SDK are not visible at run-time when the other projects are consuming this library. I tried with SL4J, and none of the logs are visible at the run time when it is used by the other projects. Should I go with log4j2? If yes, should I provide with a log4j configuration /properties file in my SDK? Will the properties/configuration be picked-up at run time from the consumer libraries? What are the best practices for this? Can you please advise?
Asked
Active
Viewed 130 times
1 Answers
1
Best practice #1: never include the logging configuration file in your jar.
Applications using your library will likely want to provide their own logging configuration. If one of the jars contains a different configuration it becomes a “fun” guessing game for these applications to figure out why their configuration isn’t working. (And depending on the classpath order, their configuration may sometimes take precedence over the configuration in the library, so sometimes it will work, just to make it extra challenging...)

Remko Popma
- 35,130
- 11
- 92
- 114
-
why should we not include the configuration file. – Vineel Apr 01 '19 at 00:17
-
What should I go with? LOG4J or SL4J? How does their logger connect with mine? – Vineel Apr 01 '19 at 08:38
-
I contribute to Log4j, I’m biased. But my detailed answer to that question is here: https://stackoverflow.com/a/41500347/1446916 – Remko Popma Apr 01 '19 at 08:40