Simplest way to output "Hello world" using SLF4J

By xngo on February 25, 2019

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 * Simplest way to output "Hello world" using SLF4J.
 * You need slf4j-api-X.jar and a binding jar(e.g. slf4j-simple-X.jar, 
 *          slf4j-log4j12-X.jar, slf4j-jdk14-X.jar, etc)
 * Bindings:         
public class SLF4JBasic
  // Pros/Cons of static Logger:
  final static Logger logger = LoggerFactory.getLogger(SLF4JBasic.class);
  public static void main(String[] args)
  {"Hello World");
    System.out.println("Hello World from System.out.");
     * You don't configure your logging on SLF4j but through the logger
     * implementation used(i.e. binding used).
     * slf4j-simple-X.jar:
     *    It's either through system property
     *      -Dorg.slf4j.simpleLogger.defaultLogLevel=debug
     *        or
     *      -In file in your classpath(     
 *            Different logger configuration file sample
// Reference:
      org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss.SSS
/* logback.xml: java -Dlogback.configurationFile=/path/to/config.xml
        You need slf4j-api-X.jar, logback-classic-X.jar and logback-core-X.jar
        Pattern definition:

        <appender name="FILE" class="ch.qos.logback.core.FileAppender">
            <pattern>%date %level [%thread] %-5level %logger{10} [%file:%line] %msg%n</pattern>
        <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        <root level="debug">
          <appender-ref ref="STDOUT" />
          <appender-ref ref="FILE" />



About the author

Xuan Ngo is the founder of He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.