My new website on Artificial Intelligence and Machine Learning

SLF4J Simple Example

SLF4J binding with simple (slf4j-simple)

Here is an example illustrating the simplest way to output "Hello world" using SLF4J-Simple. It begins by getting a logger with the name "HelloWorld". This logger is in turn used to log the message "Hello World".

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
Compiling and running HelloWorld will result in the following output being printed on the console.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See for further details.
This warning is printed because no slf4j binding could be found on your class path.

The warning will disappear as soon as you add a binding to your class path. Assuming you add slf4j-simple-1.7.13.jar so that your class path contains:
now I am adding slf4j-simple dependency to to my pom.

Now you see logging output on STDOUT with INFO level. This simple logger will default show any INFO level message or higher.

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

In order to see DEBUG messages, you would need to pass in this System Property

at your Java startup.