Top Description Fields Methods
org.slf4j

public Interface Logger

Known Direct Subinterfaces
org.slf4j.spi.LocationAwareLogger
Known Direct Implementers
org.slf4j.helpers.AbstractLogger, org.slf4j.helpers.MarkerIgnoringBase, org.slf4j.helpers.NamedLoggerBase, org.slf4j.helpers.NOPLogger, org.slf4j.helpers.SubstituteLogger
Static Imports
org.slf4j.event.EventConstants.DEBUG_INT, .EventConstants.ERROR_INT, .EventConstants.INFO_INT, .EventConstants.TRACE_INT, .EventConstants.WARN_INT, .Level.DEBUG, .Level.ERROR, .Level.INFO, .Level.TRACE, .Level.WARN

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ü

Field Summary

Modifier and TypeField and Description
public static final String
ROOT_LOGGER_NAME

Case-insensitive String constant used to retrieve the name of the root logger.

Method Summary

Modifier and TypeMethod and Description
public default LoggingEventBuilder

Returns:

LoggingEventBuilder instance as appropriate for level DEBUG
atDebug
()

Entry point for fluent-logging for org.slf4j.event.Level#DEBUG level.

public default LoggingEventBuilder

Returns:

LoggingEventBuilder instance as appropriate for level ERROR
atError
()

Entry point for fluent-logging for org.slf4j.event.Level#ERROR level.

public default LoggingEventBuilder

Returns:

LoggingEventBuilder instance as appropriate for level INFO
atInfo
()

Entry point for fluent-logging for org.slf4j.event.Level#INFO level.

public default LoggingEventBuilder

Returns:

a new LoggingEventBuilder instance as appropriate for this logger
atLevel
(Level
desired level for the event builder
level
)

Make a new LoggingEventBuilder instance as appropriate for this logger and the desired Level passed as parameter.

public default LoggingEventBuilder

Returns:

LoggingEventBuilder instance as appropriate for level TRACE
atTrace
()

Entry point for fluent-logging for org.slf4j.event.Level#TRACE level.

public default LoggingEventBuilder

Returns:

LoggingEventBuilder instance as appropriate for level WARN
atWarn
()

Entry point for fluent-logging for org.slf4j.event.Level#WARN level.

public void
debug(String
the message string to be logged
msg
)

Log a message at the DEBUG level.

public void
debug(String
the format string
format
,
Object
the argument
arg
)

Log a message at the DEBUG level according to the specified format and argument.

public void
debug(String
the format string
format
,
Object
the first argument
arg1
,
Object
the second argument
arg2
)

Log a message at the DEBUG level according to the specified format and arguments.

public void
debug(String
the format string
format
,
Object...
a list of 3 or more arguments
arguments
)

Log a message at the DEBUG level according to the specified format and arguments.

public void
debug(String
the message accompanying the exception
msg
,
Throwable
the exception (throwable) to log
t
)

Log an exception (throwable) at the DEBUG level with an accompanying message.

public void
debug(Marker
the marker data specific to this log statement
marker
,
String
the message string to be logged
msg
)

Log a message with the specific Marker at the DEBUG level.

public void
debug(Marker
the marker data specific to this log statement
marker
,
String
the format string
format
,
Object
the argument
arg
)

This method is similar to debug(String, Object) method except that the marker data is also taken into consideration.

public void
debug(Marker
the marker data specific to this log statement
marker
,
String
the format string
format
,
Object
the first argument
arg1
,
Object
the second argument
arg2
)

This method is similar to debug(String, Object, Object) method except that the marker data is also taken into consideration.

public void
debug(Marker
the marker data specific to this log statement
marker
,
String
the format string
format
,
Object...
a list of 3 or more arguments
arguments
)

This method is similar to debug(String, Object...) method except that the marker data is also taken into consideration.

public void
debug(Marker
the marker data specific to this log statement
marker
,
String
the message accompanying the exception
msg
,
Throwable
the exception (throwable) to log
t
)

This method is similar to debug(String, Throwable) method except that the marker data is also taken into consideration.

public void
error(String
the message string to be logged
msg
)

Log a message at the ERROR level.

public void
error(String
the format string
format
,
Object
the argument
arg
)

Log a message at the ERROR level according to the specified format and argument.

public void
error(String
the format string
format
,
Object
the first argument
arg1
,
Object
the second argument
arg2
)

Log a message at the ERROR level according to the specified format and arguments.

public void
error(String
the format string
format
,
Object...
a list of 3 or more arguments
arguments
)

Log a message at the ERROR level according to the specified format and arguments.

public void
error(String
the message accompanying the exception
msg
,
Throwable
the exception (throwable) to log
t
)

Log an exception (throwable) at the ERROR level with an accompanying message.

public void
error(Marker
The marker specific to this log statement
marker
,
String
the message string to be logged
msg
)

Log a message with the specific Marker at the ERROR level.

public void
error(Marker
the marker data specific to this log statement
marker
,
String
the format string
format
,
Object
the argument
arg
)

This method is similar to error(String, Object) method except that the marker data is also taken into consideration.

public void
error(Marker
the marker data specific to this log statement
marker
,
String
the format string
format
,
Object
the first argument
arg1
,
Object
the second argument
arg2
)

This method is similar to error(String, Object, Object) method except that the marker data is also taken into consideration.

public void
error(Marker
the marker data specific to this log statement
marker
,
String
the format string
format
,
Object...
a list of 3 or more arguments
arguments
)

This method is similar to error(String, Object...) method except that the marker data is also taken into consideration.

public void
error(Marker
the marker data specific to this log statement
marker
,
String
the message accompanying the exception
msg
,
Throwable
the exception (throwable) to log
t
)

This method is similar to error(String, Throwable) method except that the marker data is also taken into consideration.

public String

Returns:

name of this logger instance
getName
()

Return the name of this Logger instance.

public void
info(String
the message string to be logged
msg
)

Log a message at the INFO level.

public void
info(String
the format string
format
,
Object
the argument
arg
)

Log a message at the INFO level according to the specified format and argument.

public void
info(String
the format string
format
,
Object
the first argument
arg1
,
Object
the second argument
arg2
)

Log a message at the INFO level according to the specified format and arguments.

public void
info(String
the format string
format
,
Object...
a list of 3 or more arguments
arguments
)

Log a message at the INFO level according to the specified format and arguments.

public void
info(String
the message accompanying the exception
msg
,
Throwable
the exception (throwable) to log
t
)

Log an exception (throwable) at the INFO level with an accompanying message.

public void
info(Marker
The marker specific to this log statement
marker
,
String
the message string to be logged
msg
)

Log a message with the specific Marker at the INFO level.

public void
info(Marker
the marker data specific to this log statement
marker
,
String
the format string
format
,
Object
the argument
arg
)

This method is similar to info(String, Object) method except that the marker data is also taken into consideration.

public void
info(Marker
the marker data specific to this log statement
marker
,
String
the format string
format
,
Object
the first argument
arg1
,
Object
the second argument
arg2
)

This method is similar to info(String, Object, Object) method except that the marker data is also taken into consideration.

public void
info(Marker
the marker data specific to this log statement
marker
,
String
the format string
format
,
Object...
a list of 3 or more arguments
arguments
)

This method is similar to info(String, Object...) method except that the marker data is also taken into consideration.

public void
info(Marker
the marker data for this log statement
marker
,
String
the message accompanying the exception
msg
,
Throwable
the exception (throwable) to log
t
)

This method is similar to info(String, Throwable) method except that the marker data is also taken into consideration.

public boolean

Returns:

True if this Logger is enabled for the DEBUG level, false otherwise.
isDebugEnabled
()

Is the logger instance enabled for the DEBUG level?

public boolean

Returns:

True if this Logger is enabled for the DEBUG level, false otherwise.
isDebugEnabled
(Marker
The marker data to take into consideration
marker
)

Similar to isDebugEnabled() method except that the marker data is also taken into account.

public default boolean

Returns:

true if enabled, false otherwise.
isEnabledForLevel
(Level level)

Returns whether this Logger is enabled for a given Level.

public boolean

Returns:

True if this Logger is enabled for the ERROR level, false otherwise.
isErrorEnabled
()

Is the logger instance enabled for the ERROR level?

public boolean

Returns:

True if this Logger is enabled for the ERROR level, false otherwise.
isErrorEnabled
(Marker
The marker data to take into consideration
marker
)

Similar to isErrorEnabled() method except that the marker data is also taken into consideration.

public boolean

Returns:

True if this Logger is enabled for the INFO level, false otherwise.
isInfoEnabled
()

Is the logger instance enabled for the INFO level?

public boolean

Returns:

true if this Logger is enabled for the INFO level, false otherwise.
isInfoEnabled
(Marker
The marker data to take into consideration
marker
)

Similar to isInfoEnabled() method except that the marker data is also taken into consideration.

public boolean

Returns:

True if this Logger is enabled for the TRACE level, false otherwise.
isTraceEnabled
()

Is the logger instance enabled for the TRACE level?

public boolean

Returns:

True if this Logger is enabled for the TRACE level, false otherwise.
isTraceEnabled
(Marker
The marker data to take into consideration
marker
)

Similar to isTraceEnabled() method except that the marker data is also taken into account.

public boolean

Returns:

True if this Logger is enabled for the WARN level, false otherwise.
isWarnEnabled
()

Is the logger instance enabled for the WARN level?

public boolean

Returns:

True if this Logger is enabled for the WARN level, false otherwise.
isWarnEnabled
(Marker
The marker data to take into consideration
marker
)

Similar to isWarnEnabled() method except that the marker data is also taken into consideration.

public default LoggingEventBuilder

Returns:

a new LoggingEventBuilder instance as appropriate for this logger
makeLoggingEventBuilder
(Level
desired level for the event builder
level
)

Make a new LoggingEventBuilder instance as appropriate for this logger implementation.

public void
trace(String
the message string to be logged
msg
)

Log a message at the TRACE level.

public void
trace(String
the format string
format
,
Object
the argument
arg
)

Log a message at the TRACE level according to the specified format and argument.

public void
trace(String
the format string
format
,
Object
the first argument
arg1
,
Object
the second argument
arg2
)

Log a message at the TRACE level according to the specified format and arguments.

public void
trace(String
the format string
format
,
Object...
a list of 3 or more arguments
arguments
)

Log a message at the TRACE level according to the specified format and arguments.

public void
trace(String
the message accompanying the exception
msg
,
Throwable
the exception (throwable) to log
t
)

Log an exception (throwable) at the TRACE level with an accompanying message.

public void
trace(Marker
the marker data specific to this log statement
marker
,
String
the message string to be logged
msg
)

Log a message with the specific Marker at the TRACE level.

public void
trace(Marker
the marker data specific to this log statement
marker
,
String
the format string
format
,
Object
the argument
arg
)

This method is similar to trace(String, Object) method except that the marker data is also taken into consideration.

public void
trace(Marker
the marker data specific to this log statement
marker
,
String
the format string
format
,
Object
the first argument
arg1
,
Object
the second argument
arg2
)

This method is similar to trace(String, Object, Object) method except that the marker data is also taken into consideration.

public void
trace(Marker
the marker data specific to this log statement
marker
,
String
the format string
format
,
Object...
an array of arguments
argArray
)

This method is similar to trace(String, Object...) method except that the marker data is also taken into consideration.

public void
trace(Marker
the marker data specific to this log statement
marker
,
String
the message accompanying the exception
msg
,
Throwable
the exception (throwable) to log
t
)

This method is similar to trace(String, Throwable) method except that the marker data is also taken into consideration.

public void
warn(String
the message string to be logged
msg
)

Log a message at the WARN level.

public void
warn(String
the format string
format
,
Object
the argument
arg
)

Log a message at the WARN level according to the specified format and argument.

public void
warn(String
the format string
format
,
Object...
a list of 3 or more arguments
arguments
)

Log a message at the WARN level according to the specified format and arguments.

public void
warn(String
the format string
format
,
Object
the first argument
arg1
,
Object
the second argument
arg2
)

Log a message at the WARN level according to the specified format and arguments.

public void
warn(String
the message accompanying the exception
msg
,
Throwable
the exception (throwable) to log
t
)

Log an exception (throwable) at the WARN level with an accompanying message.

public void
warn(Marker
The marker specific to this log statement
marker
,
String
the message string to be logged
msg
)

Log a message with the specific Marker at the WARN level.

public void
warn(Marker
the marker data specific to this log statement
marker
,
String
the format string
format
,
Object
the argument
arg
)

This method is similar to warn(String, Object) method except that the marker data is also taken into consideration.

public void
warn(Marker
the marker data specific to this log statement
marker
,
String
the format string
format
,
Object
the first argument
arg1
,
Object
the second argument
arg2
)

This method is similar to warn(String, Object, Object) method except that the marker data is also taken into consideration.

public void
warn(Marker
the marker data specific to this log statement
marker
,
String
the format string
format
,
Object...
a list of 3 or more arguments
arguments
)

This method is similar to warn(String, Object...) method except that the marker data is also taken into consideration.

public void
warn(Marker
the marker data for this log statement
marker
,
String
the message accompanying the exception
msg
,
Throwable
the exception (throwable) to log
t
)

This method is similar to warn(String, Throwable) method except that the marker data is also taken into consideration.