public class TestLogger extends Object implements Logger
Implementation of Logger which stores LoggingEvents in memory and provides methods
to access and remove them in order to facilitate writing tests that assert particular logging calls were made.
LoggingEvents 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).
ROOT_LOGGER_NAME| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all
LoggingEvents logged by this thread and resets the enabled levels of the logger
to Level.enablableValueSet() for this thread. |
void |
clearAll()
Removes ALL
LoggingEvents logged on this logger, regardless of thread,
and resets the enabled levels of the logger to Level.enablableValueSet()
for ALL threads. |
void |
debug(Marker marker,
String msg) |
void |
debug(Marker marker,
String format,
Object... args) |
void |
debug(Marker marker,
String format,
Object arg) |
void |
debug(Marker marker,
String format,
Object arg1,
Object arg2) |
void |
debug(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(Marker marker,
String msg) |
void |
error(Marker marker,
String format,
Object... args) |
void |
error(Marker marker,
String format,
Object arg) |
void |
error(Marker marker,
String format,
Object arg1,
Object arg2) |
void |
error(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) |
ImmutableList<LoggingEvent> |
getAllLoggingEvents() |
ImmutableSet<uk.org.lidalia.slf4jext.Level> |
getEnabledLevels() |
ImmutableList<LoggingEvent> |
getLoggingEvents() |
String |
getName() |
void |
info(Marker marker,
String msg) |
void |
info(Marker marker,
String format,
Object... args) |
void |
info(Marker marker,
String format,
Object arg) |
void |
info(Marker marker,
String format,
Object arg1,
Object arg2) |
void |
info(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(Marker marker) |
boolean |
isErrorEnabled() |
boolean |
isErrorEnabled(Marker marker) |
boolean |
isInfoEnabled() |
boolean |
isInfoEnabled(Marker marker) |
boolean |
isTraceEnabled() |
boolean |
isTraceEnabled(Marker marker) |
boolean |
isWarnEnabled() |
boolean |
isWarnEnabled(Marker marker) |
void |
setEnabledLevels(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(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(Marker marker,
String msg) |
void |
trace(Marker marker,
String format,
Object... args) |
void |
trace(Marker marker,
String format,
Object arg) |
void |
trace(Marker marker,
String format,
Object arg1,
Object arg2) |
void |
trace(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(Marker marker,
String msg) |
void |
warn(Marker marker,
String format,
Object... args) |
void |
warn(Marker marker,
String format,
Object arg) |
void |
warn(Marker marker,
String format,
Object arg1,
Object arg2) |
void |
warn(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 void clear()
LoggingEvents logged by this thread and resets the enabled levels of the logger
to Level.enablableValueSet() for this thread.public void clearAll()
LoggingEvents logged on this logger, regardless of thread,
and resets the enabled levels of the logger to Level.enablableValueSet()
for ALL threads.public ImmutableList<LoggingEvent> getLoggingEvents()
LoggingEvents logged on this logger by this threadpublic ImmutableList<LoggingEvent> getAllLoggingEvents()
LoggingEvents logged on this logger by ANY threadpublic boolean isTraceEnabled()
isTraceEnabled in interface Loggerpublic boolean isTraceEnabled(Marker marker)
isTraceEnabled in interface Loggerpublic boolean isDebugEnabled()
isDebugEnabled in interface Loggerpublic boolean isDebugEnabled(Marker marker)
isDebugEnabled in interface Loggerpublic boolean isInfoEnabled()
isInfoEnabled in interface Loggerpublic boolean isInfoEnabled(Marker marker)
isInfoEnabled in interface Loggerpublic boolean isWarnEnabled()
isWarnEnabled in interface Loggerpublic boolean isWarnEnabled(Marker marker)
isWarnEnabled in interface Loggerpublic boolean isErrorEnabled()
isErrorEnabled in interface Loggerpublic boolean isErrorEnabled(Marker marker)
isErrorEnabled in interface Loggerpublic ImmutableSet<uk.org.lidalia.slf4jext.Level> getEnabledLevels()
public void setEnabledLevels(ImmutableSet<uk.org.lidalia.slf4jext.Level> enabledLevels)
ConventionalLevelHierarchyenabledLevels - 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(ImmutableSet<uk.org.lidalia.slf4jext.Level> enabledLevelsForAllThreads)
ConventionalLevelHierarchyenabledLevelsForAllThreads - 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 © 2015. All rights reserved.