public class TestLogger extends Object implements org.slf4j.Logger
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(ImmutableSet)
, setEnabledLevels(Level...)
,
setEnabledLevelsForAllThreads(ImmutableSet)
, setEnabledLevelsForAllThreads(Level...)
and the various
isXxxxxEnabled() methods make no assumptions about this hierarchy. If you wish to use traditional hierarchical setups you may
do so by passing the constants in ConventionalLevelHierarchy
to
setEnabledLevels(ImmutableSet)
or setEnabledLevelsForAllThreads(ImmutableSet)
.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 Level.enablableValueSet() 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 Level.enablableValueSet()
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) |
com.google.common.collect.ImmutableList<LoggingEvent> |
getAllLoggingEvents() |
com.google.common.collect.ImmutableSet<uk.org.lidalia.slf4jext.Level> |
getEnabledLevels() |
com.google.common.collect.ImmutableList<LoggingEvent> |
getLoggingEvents() |
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 |
setEnabledLevels(com.google.common.collect.ImmutableSet<uk.org.lidalia.slf4jext.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(uk.org.lidalia.slf4jext.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(com.google.common.collect.ImmutableSet<uk.org.lidalia.slf4jext.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(uk.org.lidalia.slf4jext.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 void clear()
LoggingEvent
s logged by this thread and resets the enabled levels of the logger
to Level.enablableValueSet()
for this thread.public void clearAll()
LoggingEvent
s logged on this logger, regardless of thread,
and resets the enabled levels of the logger to Level.enablableValueSet()
for ALL threads.public com.google.common.collect.ImmutableList<LoggingEvent> getLoggingEvents()
LoggingEvent
s logged on this logger by this threadpublic com.google.common.collect.ImmutableList<LoggingEvent> getAllLoggingEvents()
LoggingEvent
s logged on this logger by ANY threadpublic 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 com.google.common.collect.ImmutableSet<uk.org.lidalia.slf4jext.Level> getEnabledLevels()
public void setEnabledLevels(com.google.common.collect.ImmutableSet<uk.org.lidalia.slf4jext.Level> enabledLevels)
ConventionalLevelHierarchy
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(uk.org.lidalia.slf4jext.Level... enabledLevels)
ConventionalLevelHierarchy
to setEnabledLevels(ImmutableSet)
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(com.google.common.collect.ImmutableSet<uk.org.lidalia.slf4jext.Level> enabledLevelsForAllThreads)
ConventionalLevelHierarchy
enabledLevelsForAllThreads
- levels which will be considered enabled for this logger IN ALL THREADSpublic void setEnabledLevelsForAllThreads(uk.org.lidalia.slf4jext.Level... enabledLevelsForAllThreads)
ConventionalLevelHierarchy
to setEnabledLevelsForAllThreads(ImmutableSet)
enabledLevelsForAllThreads
- levels which will be considered enabled for this logger IN ALL THREADSCopyright © 2014. All Rights Reserved.