Package tech.jhipster.test
Class LogbackRecorder
java.lang.Object
tech.jhipster.test.LogbackRecorder
@ConditionalOnClass(ch.qos.logback.classic.LoggerContext.class)
public class LogbackRecorder
extends Object
Utility, mainly for unit tests, to assert content written to logback. A classical usage would be
the following.
LogbackRecorder recorder = LogbackRecorder.forClass(TestedClass.class)
.reset()
.capture(Level.WARN.name());
// do something that logs
List<LogbackRecorder.Event> events = recorder.release().play();
// perform assertions on the events
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConstantCAPTURE_EXCEPTION_MESSAGE="Already capturing"static final StringConstantDEFAULT_LEVEL="ALL"static final booleanConstantDEFAULT_MUTE=truestatic final StringConstantLOGBACK_EXCEPTION_MESSAGE="Expected logback"static final StringConstantRELEASE_EXCEPTION_MESSAGE="Not currently capturing" -
Method Summary
Modifier and TypeMethodDescriptionStart capturing whatever is logged for this level of worse.static LogbackRecorderCreate a recorder for a logback logger identified by the class name.static LogbackRecorderforLogger(org.slf4j.Logger logger) Create a recorder for a logback logger.static LogbackRecorderCreate a recorder for a logback logger identified by its name.play()Return all recorded events.release()Stop recording and detach from the logger.reset()Resets the logger by clearing everything that was recorded so far.
-
Field Details
-
DEFAULT_MUTE
public static final boolean DEFAULT_MUTEConstantDEFAULT_MUTE=true- See Also:
-
DEFAULT_LEVEL
ConstantDEFAULT_LEVEL="ALL"- See Also:
-
LOGBACK_EXCEPTION_MESSAGE
ConstantLOGBACK_EXCEPTION_MESSAGE="Expected logback"- See Also:
-
CAPTURE_EXCEPTION_MESSAGE
ConstantCAPTURE_EXCEPTION_MESSAGE="Already capturing"- See Also:
-
RELEASE_EXCEPTION_MESSAGE
ConstantRELEASE_EXCEPTION_MESSAGE="Not currently capturing"- See Also:
-
-
Method Details
-
forClass
Create a recorder for a logback logger identified by the class name. Instances of a recorder are cached per logger. Make sure to reset it before starting capture.- Parameters:
clazz- class whose logger as its name- Returns:
- the recorder for this class
-
forName
Create a recorder for a logback logger identified by its name. Instances of a recorder are cached per logger. Make sure to reset it before starting capture.- Parameters:
name- the name of the logger- Returns:
- the recorder for this class
-
forLogger
Create a recorder for a logback logger. Instances of a recorder are cached per logger. Make sure to reset it before starting capture.- Parameters:
logger- the logger to record- Returns:
- the recorder for this logger
-
reset
Resets the logger by clearing everything that was recorded so far.- Returns:
- this
-
capture
Start capturing whatever is logged for this level of worse.- Parameters:
level- the level at which to start capturing- Returns:
- this
-
release
Stop recording and detach from the logger.- Returns:
- this
-
play
Return all recorded events.- Returns:
- all recorded events so far
-