I'm writing a library and I use sfl4j to handle logging.
I think it's good idea as long as every body can provide it's own implementation and then, the log provided by my application will be handled correctly.
But I don't know if I have to provide an implementation as a transitive dependency or not.
Exemple:
If I only provide that:
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
The user of my lib can choose the implementation, but if he just add my lib without reading configuration, it will not work
Otherwise, if I provide that:
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
My lib will work correctly just when adding dependency to it, but If the user want to use an other slf4j, he will have to exclude mine.
What do you thing about that?
Unlike log4j, SLF4J (Simple Logging Facade for Java) is not an implementation of logging framework, it is an abstraction for all those logging frameworks in Java similar to log4J. Therefore, you cannot compare both. However, it is always difficult to prefer one between the two.
One of the most popular solutions for the Java world is the Apache Log4j 2 framework.
SLF4J and Apache commons logging (jcl) )are widely used logging wrappers that will use discovery at run time to check for pluggable frameworks like log4j,log4j2, logback in the classpaths that provide implementations.
Use structured logging Human readable logs are helpful, but structured logs add value, especially as an application's logs become more complex or as request throughput increases. Structured logging provides a well-defined format for your log entries so you can more easily parse, query, and process them for analytics.
You never provide a log implementation. The client application has to do so. Otherwhise this would be a violation of separation of concerns. Don't do any assumptions about an unknown client.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With