SLF4J with JDK14 Example

SLF4J binding with JDK14 (slf4j-jdk14)

Now we can experiment and swap different logger implementations, but your application code can remain the same. All we need is to add slf4j-jdk14 with another popular logger implementation, such as the Log4j.We can use a Java class to configure the Java Logging API. You do so by specifying the name of the class in the JVM parameter java.util.logging.config.class. It is the constructor of that class that should load the configuration and apply it to the Logger's in the hierarchy.

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) {"Hi, Welcome to SLF4J exmaple");

for now I am adding below dependency for maven pom.xml
Now the configuration for JDK logging is a bit difficult to work with. Not only need a config file, such as src/main/resources/, but you would also need to add a System properties in order to have it pick it up. Here is an example to get you started:
handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler
# Write 10MB before rotating this file
# Number of rotating files to be used
project structure after maven build.

SLF4J with JDK14 workspace

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

Dec 13, 2015 3:58:38 PM com.javavillage.slf4j.SLF4JSample main
INFO: Hi, Welcome to SLF4J exmaple