Wednesday, July 13, 2016

slf4j logging -- log4j / logback

Simple Logging Facade for Java (SLF4J) is an API designed to give generic access to many logging frameworks
- log4j
- logback

To decide log4j or logback depends at the time of deployment ,agnostic to code

ex-

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HelloWorld
{
    public static void main(String[] args)
    {
        Logger logger = LoggerFactory.getLogger(HelloWorld.class);
        logger.info("Hello World");
    }
}


For above code all you need is slf4j 

  1. SLF4j binding jar file
  2. Desired logging framework jar files (log4j or logback)
There are reasons to use logback ovr log4j because of all the improvments.
Please read below -