Install with maven
<dependency>
<groupId>io.github.hakky54</groupId>
<artifactId>yaslf4j</artifactId>
<version>1.0.1</version>
</dependency>
implementation 'io.github.hakky54:yaslf4j:1.0.1'
libraryDependencies += "io.github.hakky54" % "yaslf4j" % "1.0.1"
<dependency org="io.github.hakky54" name="yaslf4j" rev="1.0.1" />
YASLF4J is a logging facade / api which will delegate application logs to the underlying provider. It will either delegate it to SLF4J api if present, or else Log4j2 api if present or fallback to Java Util Logging Logger.
When a library owner is using SLF4J or Log4j2 the end-user will end up getting that library as a transitive dependency. The end-user needs to either provide a logging implementation or omit it. When not providing an implementation the end-user will also get the following error message:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
YASLF4J is just a simple logging api which is capable of logging. It will use SLF4J as logging api if it is present on the classpath of the end-user, but it won't provide it as a transitive dependency. The same goes for Log4j2. So the end-user may provide a logging binding but is not required and also won't get bothered if it is absent.
- The end-user won't get a transitive dependency on SLF4J or Log4j2
- The end-user won't get warning from SLF4J or Log4j2 when not having SLF4J or Log4j2 on the classpath
- It will use either SLF4J or Log4j2 if it is present at the classpath or fallback to Java Util Logging Logger
- Plug & play
- Java 8
- Java 11
- Java 15
import nl.altindag.log.Logger;
import nl.altindag.log.LoggerFactory;
public class FooService {
private static final Logger LOGGER = LoggerFactory.getLogger(FooService.class);
public void sayHello() {
LOGGER.info("Keyboard not responding. Press any key to continue...");
LOGGER.warn("Congratulations, you are pregnant!");
}
}
There are plenty of ways to contribute to this project:
- Give it a star
- Join the Gitter room and leave a feedback or help with answering users questions
- Submit a PR