The Simple Logging Facade for Java (SLF4J) serves as a simple facade or abstraction for various logging frameworks (e.g. java.util.logging, logback, log4j) allowing the end user to plug in the desired logging framework at deployment time.
You need to add this dependency to the Maven project : (pom.xml)
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.25</version> </dependency> <!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic --> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> </dependency>
Usage example :
import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class HelloWorld { public static final Logger LOGGER = LoggerFactory.getLogger(HelloWorld.class); public static void main(String[] args) { System.out.println("Hello,World!!"); LOGGER.info("Hello World"); LOGGER.info("{}", "Informational message"); } }
You can print different log level messages and their hierarchy : (low to high)
- TRACE
- DEBUG
- INFO
- WARN
- ERROR