My new website on Artificial Intelligence and Machine Learning www.aimlfront.com

SLF4J binding with Logback

The logback logger implementation is a super quality implementation. If you intend to write serious code that go into production, you may want to evaluate this option..

package com.javavillage.slf4j;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SLF4JSample {

	private static Logger LOGGER = LoggerFactory.getLogger(SLF4JSample.class);
    public static void main(String[] args) {
        LOGGER.info("Hi, Welcome to SLF4J exmaple");
    }

}
for now I am adding below dependency for maven pom.xml
<dependency>
	<groupId>org.slf4j</groupId>
	<artifactId>slf4j-api</artifactId>
	<version>1.7.13</version>
</dependency>
<dependency>
	<groupId>ch.qos.logback</groupId>
	<artifactId>logback-classic</artifactId>
	<version>1.0.13</version>
</dependency>
logback.xml
Here is a sample of configuration src/main/resources/logback.xml to get things started.
<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <logger name="javavillage" level="DEBUG"/>

  <root level="INFO">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>
project structure after maven build.

SLF4J with JDK14 workspace

Now you see logging output on STDOUT with INFO level..

16:26:05.079 [main] INFO  com.javavillage.slf4j.SLF4JSample - Hi, Welcome to SLF4J exmaple