Package org.slf4j

Interface Logger

All Known Subinterfaces:
LocationAwareLogger
All Known Implementing Classes:
AbstractLogger, EventRecordingLogger, JDK14LoggerAdapter, LegacyAbstractLogger, LocLogger, LoggerWrapper, MarkerIgnoringBase, NOPLogger, Reload4jLoggerAdapter, SimpleLogger, SubstituteLogger, XLogger

public interface Logger
The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that logging takes place through concrete implementations of this interface.

Typical usage pattern:

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

 public class Wombat {

   final static Logger logger = LoggerFactory.getLogger(Wombat.class);
   Integer t;
   Integer oldT;

   public void setTemperature(Integer temperature) {
     oldT = t;
     t = temperature;
     logger.debug("Temperature set to {}. Old temperature was {}.", t, oldT);
     if (temperature.intValue() > 50) {
       logger.info("Temperature has risen above 50 degrees.");
     }
   }
 }
 

Note that version 2.0 of the SLF4J API introduces a fluent api, the most significant API change to occur in the last 20 years.

Be sure to read the FAQ entry relating to parameterized logging. Note that logging statements can be parameterized in presence of an exception/throwable.

Once you are comfortable using loggers, i.e. instances of this interface, consider using MDC as well as Markers.

Author:
Ceki Gülcü