public class TestLogger extends Object implements org.slf4j.Logger, org.slf4j.spi.LoggingEventAware
Logger
which stores LoggingEvent
s in memory and provides
methods to access and remove them in order to facilitate writing tests that assert particular
logging calls were made.
LoggingEvent
s are stored in both an ThreadLocal
and a normal List
. The
getLoggingEvents()
and clear()
methods reference the ThreadLocal
events. The getAllLoggingEvents()
and clearAll()
methods reference all events
logged on this Logger. This is in order to facilitate parallelising tests - tests that use the
thread local methods can be parallelised.
By default all Levels are enabled. It is important to note that the conventional hierarchical
notion of Levels, where info being enabled implies warn and error being enabled, is not a
requirement of the SLF4J API, so the setEnabledLevels(Collection)
, setEnabledLevels(Level...)
, setEnabledLevelsForAllThreads(Collection)
, setEnabledLevelsForAllThreads(Level...)
and the various isXxxxxEnabled() methods make no
assumptions about this hierarchy.
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all
LoggingEvent s logged by this thread and resets the enabled levels of the
logger to all levels for this thread. |
void |
clearAll()
Removes ALL
LoggingEvent s logged on this logger, regardless of thread, and resets the
enabled levels of the logger to all levels for ALL threads. |
void |
debug(org.slf4j.Marker marker,
String msg) |
void |
debug(org.slf4j.Marker marker,
String format,
Object... args) |
void |
debug(org.slf4j.Marker marker,
String format,
Object arg) |
void |
debug(org.slf4j.Marker marker,
String format,
Object arg1,
Object arg2) |
void |
debug(org.slf4j.Marker marker,
String msg,
Throwable throwable) |
void |
debug(String message) |
void |
debug(String format,
Object... args) |
void |
debug(String format,
Object arg) |
void |
debug(String format,
Object arg1,
Object arg2) |
void |
debug(String msg,
Throwable throwable) |
void |
error(org.slf4j.Marker marker,
String msg) |
void |
error(org.slf4j.Marker marker,
String format,
Object... args) |
void |
error(org.slf4j.Marker marker,
String format,
Object arg) |
void |
error(org.slf4j.Marker marker,
String format,
Object arg1,
Object arg2) |
void |
error(org.slf4j.Marker marker,
String msg,
Throwable throwable) |
void |
error(String message) |
void |
error(String format,
Object... args) |
void |
error(String format,
Object arg) |
void |
error(String format,
Object arg1,
Object arg2) |
void |
error(String msg,
Throwable throwable) |
List<LoggingEvent> |
getAllLoggingEvents()
Get all
LoggingEvent s logged on this logger by ANY thread. |
Set<org.slf4j.event.Level> |
getEnabledLevels()
Get the levels enabled for this logger on this thread.
|
List<LoggingEvent> |
getLoggingEvents()
Get all
LoggingEvent s logged on this logger by this thread. |
String |
getName() |
void |
info(org.slf4j.Marker marker,
String msg) |
void |
info(org.slf4j.Marker marker,
String format,
Object... args) |
void |
info(org.slf4j.Marker marker,
String format,
Object arg) |
void |
info(org.slf4j.Marker marker,
String format,
Object arg1,
Object arg2) |
void |
info(org.slf4j.Marker marker,
String msg,
Throwable throwable) |
void |
info(String message) |
void |
info(String format,
Object... args) |
void |
info(String format,
Object arg) |
void |
info(String format,
Object arg1,
Object arg2) |
void |
info(String msg,
Throwable throwable) |
boolean |
isDebugEnabled() |
boolean |
isDebugEnabled(org.slf4j.Marker marker) |
boolean |
isErrorEnabled() |
boolean |
isErrorEnabled(org.slf4j.Marker marker) |
boolean |
isInfoEnabled() |
boolean |
isInfoEnabled(org.slf4j.Marker marker) |
boolean |
isTraceEnabled() |
boolean |
isTraceEnabled(org.slf4j.Marker marker) |
boolean |
isWarnEnabled() |
boolean |
isWarnEnabled(org.slf4j.Marker marker) |
void |
log(org.slf4j.event.LoggingEvent event) |
org.slf4j.spi.LoggingEventBuilder |
makeLoggingEventBuilder(org.slf4j.event.Level level)
Make a
TestLoggingEventBuilder . |
void |
setEnabledLevels(Collection<org.slf4j.event.Level> enabledLevels)
The conventional hierarchical notion of Levels, where info being enabled implies warn and error
being enabled, is not a requirement of the SLF4J API, so all levels you wish to enable must be
passed explicitly to this method.
|
void |
setEnabledLevels(org.slf4j.event.Level... enabledLevels)
The conventional hierarchical notion of Levels, where info being enabled implies warn and error
being enabled, is not a requirement of the SLF4J API, so all levels you wish to enable must be
passed explicitly to this method.
|
void |
setEnabledLevelsForAllThreads(Collection<org.slf4j.event.Level> enabledLevelsForAllThreads)
The conventional hierarchical notion of Levels, where info being enabled implies warn and error
being enabled, is not a requirement of the SLF4J API, so all levels you wish to enable must be
passed explicitly to this method.
|
void |
setEnabledLevelsForAllThreads(org.slf4j.event.Level... enabledLevelsForAllThreads)
The conventional hierarchical notion of Levels, where info being enabled implies warn and error
being enabled, is not a requirement of the SLF4J API, so all levels you wish to enable must be
passed explicitly to this method.
|
void |
trace(org.slf4j.Marker marker,
String msg) |
void |
trace(org.slf4j.Marker marker,
String format,
Object... args) |
void |
trace(org.slf4j.Marker marker,
String format,
Object arg) |
void |
trace(org.slf4j.Marker marker,
String format,
Object arg1,
Object arg2) |
void |
trace(org.slf4j.Marker marker,
String msg,
Throwable throwable) |
void |
trace(String message) |
void |
trace(String format,
Object... args) |
void |
trace(String format,
Object arg) |
void |
trace(String format,
Object arg1,
Object arg2) |
void |
trace(String msg,
Throwable throwable) |
void |
warn(org.slf4j.Marker marker,
String msg) |
void |
warn(org.slf4j.Marker marker,
String format,
Object... args) |
void |
warn(org.slf4j.Marker marker,
String format,
Object arg) |
void |
warn(org.slf4j.Marker marker,
String format,
Object arg1,
Object arg2) |
void |
warn(org.slf4j.Marker marker,
String msg,
Throwable throwable) |
void |
warn(String message) |
void |
warn(String format,
Object... args) |
void |
warn(String format,
Object arg) |
void |
warn(String format,
Object arg1,
Object arg2) |
void |
warn(String msg,
Throwable throwable) |
public String getName()
getName
in interface org.slf4j.Logger
public org.slf4j.spi.LoggingEventBuilder makeLoggingEventBuilder(org.slf4j.event.Level level)
TestLoggingEventBuilder
.makeLoggingEventBuilder
in interface org.slf4j.Logger
public void clear()
LoggingEvent
s logged by this thread and resets the enabled levels of the
logger to all levels for this thread.public void clearAll()
LoggingEvent
s logged on this logger, regardless of thread, and resets the
enabled levels of the logger to all levels for ALL threads.public List<LoggingEvent> getLoggingEvents()
LoggingEvent
s logged on this logger by this thread.LoggingEvent
s as an unmodifiable List
.public List<LoggingEvent> getAllLoggingEvents()
LoggingEvent
s logged on this logger by ANY thread.LoggingEvent
s as an unmodifiable List
.public boolean isTraceEnabled()
isTraceEnabled
in interface org.slf4j.Logger
public void trace(String message)
trace
in interface org.slf4j.Logger
public void trace(String format, Object arg)
trace
in interface org.slf4j.Logger
public void trace(String format, Object arg1, Object arg2)
trace
in interface org.slf4j.Logger
public void trace(String format, Object... args)
trace
in interface org.slf4j.Logger
public void trace(String msg, Throwable throwable)
trace
in interface org.slf4j.Logger
public boolean isTraceEnabled(org.slf4j.Marker marker)
isTraceEnabled
in interface org.slf4j.Logger
public void trace(org.slf4j.Marker marker, String msg)
trace
in interface org.slf4j.Logger
public void trace(org.slf4j.Marker marker, String format, Object arg)
trace
in interface org.slf4j.Logger
public void trace(org.slf4j.Marker marker, String format, Object arg1, Object arg2)
trace
in interface org.slf4j.Logger
public void trace(org.slf4j.Marker marker, String format, Object... args)
trace
in interface org.slf4j.Logger
public void trace(org.slf4j.Marker marker, String msg, Throwable throwable)
trace
in interface org.slf4j.Logger
public boolean isDebugEnabled()
isDebugEnabled
in interface org.slf4j.Logger
public void debug(String message)
debug
in interface org.slf4j.Logger
public void debug(String format, Object arg)
debug
in interface org.slf4j.Logger
public void debug(String format, Object arg1, Object arg2)
debug
in interface org.slf4j.Logger
public void debug(String format, Object... args)
debug
in interface org.slf4j.Logger
public void debug(String msg, Throwable throwable)
debug
in interface org.slf4j.Logger
public boolean isDebugEnabled(org.slf4j.Marker marker)
isDebugEnabled
in interface org.slf4j.Logger
public void debug(org.slf4j.Marker marker, String msg)
debug
in interface org.slf4j.Logger
public void debug(org.slf4j.Marker marker, String format, Object arg)
debug
in interface org.slf4j.Logger
public void debug(org.slf4j.Marker marker, String format, Object arg1, Object arg2)
debug
in interface org.slf4j.Logger
public void debug(org.slf4j.Marker marker, String format, Object... args)
debug
in interface org.slf4j.Logger
public void debug(org.slf4j.Marker marker, String msg, Throwable throwable)
debug
in interface org.slf4j.Logger
public boolean isInfoEnabled()
isInfoEnabled
in interface org.slf4j.Logger
public void info(String message)
info
in interface org.slf4j.Logger
public void info(String format, Object arg1, Object arg2)
info
in interface org.slf4j.Logger
public void info(String format, Object... args)
info
in interface org.slf4j.Logger
public void info(String msg, Throwable throwable)
info
in interface org.slf4j.Logger
public boolean isInfoEnabled(org.slf4j.Marker marker)
isInfoEnabled
in interface org.slf4j.Logger
public void info(org.slf4j.Marker marker, String msg)
info
in interface org.slf4j.Logger
public void info(org.slf4j.Marker marker, String format, Object arg)
info
in interface org.slf4j.Logger
public void info(org.slf4j.Marker marker, String format, Object arg1, Object arg2)
info
in interface org.slf4j.Logger
public void info(org.slf4j.Marker marker, String format, Object... args)
info
in interface org.slf4j.Logger
public void info(org.slf4j.Marker marker, String msg, Throwable throwable)
info
in interface org.slf4j.Logger
public boolean isWarnEnabled()
isWarnEnabled
in interface org.slf4j.Logger
public void warn(String message)
warn
in interface org.slf4j.Logger
public void warn(String format, Object arg1, Object arg2)
warn
in interface org.slf4j.Logger
public void warn(String format, Object... args)
warn
in interface org.slf4j.Logger
public void warn(String msg, Throwable throwable)
warn
in interface org.slf4j.Logger
public boolean isWarnEnabled(org.slf4j.Marker marker)
isWarnEnabled
in interface org.slf4j.Logger
public void warn(org.slf4j.Marker marker, String msg)
warn
in interface org.slf4j.Logger
public void warn(org.slf4j.Marker marker, String format, Object arg)
warn
in interface org.slf4j.Logger
public void warn(org.slf4j.Marker marker, String format, Object arg1, Object arg2)
warn
in interface org.slf4j.Logger
public void warn(org.slf4j.Marker marker, String format, Object... args)
warn
in interface org.slf4j.Logger
public void warn(org.slf4j.Marker marker, String msg, Throwable throwable)
warn
in interface org.slf4j.Logger
public boolean isErrorEnabled()
isErrorEnabled
in interface org.slf4j.Logger
public void error(String message)
error
in interface org.slf4j.Logger
public void error(String format, Object arg)
error
in interface org.slf4j.Logger
public void error(String format, Object arg1, Object arg2)
error
in interface org.slf4j.Logger
public void error(String format, Object... args)
error
in interface org.slf4j.Logger
public void error(String msg, Throwable throwable)
error
in interface org.slf4j.Logger
public boolean isErrorEnabled(org.slf4j.Marker marker)
isErrorEnabled
in interface org.slf4j.Logger
public void error(org.slf4j.Marker marker, String msg)
error
in interface org.slf4j.Logger
public void error(org.slf4j.Marker marker, String format, Object arg)
error
in interface org.slf4j.Logger
public void error(org.slf4j.Marker marker, String format, Object arg1, Object arg2)
error
in interface org.slf4j.Logger
public void error(org.slf4j.Marker marker, String format, Object... args)
error
in interface org.slf4j.Logger
public void error(org.slf4j.Marker marker, String msg, Throwable throwable)
error
in interface org.slf4j.Logger
public void log(org.slf4j.event.LoggingEvent event)
log
in interface org.slf4j.spi.LoggingEventAware
public Set<org.slf4j.event.Level> getEnabledLevels()
Set
.public void setEnabledLevels(Collection<org.slf4j.event.Level> enabledLevels)
enabledLevels
- levels which will be considered enabled for this logger IN THIS THREAD;
does not affect enabled levels for this logger in other threadspublic void setEnabledLevels(org.slf4j.event.Level... enabledLevels)
enabledLevels
- levels which will be considered enabled for this logger IN THIS THREAD;
does not affect enabled levels for this logger in other threadspublic void setEnabledLevelsForAllThreads(Collection<org.slf4j.event.Level> enabledLevelsForAllThreads)
enabledLevelsForAllThreads
- levels which will be considered enabled for this logger IN
ALL THREADSpublic void setEnabledLevelsForAllThreads(org.slf4j.event.Level... enabledLevelsForAllThreads)
enabledLevelsForAllThreads
- levels which will be considered enabled for this logger IN
ALL THREADSCopyright © 2023. All rights reserved.