Package io.github.jhipster.test
Class LogbackRecorder
- java.lang.Object
-
- io.github.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 Modifier and Type Class Description static classLogbackRecorder.EventA recorded event.
-
Field Summary
Fields Modifier and Type Field Description static StringCAPTURE_EXCEPTION_MESSAGEConstantCAPTURE_EXCEPTION_MESSAGE="Already capturing"static StringDEFAULT_LEVELConstantDEFAULT_LEVEL="ALL"static booleanDEFAULT_MUTEConstantDEFAULT_MUTE=truestatic StringLOGBACK_EXCEPTION_MESSAGEConstantLOGBACK_EXCEPTION_MESSAGE="Expected logback"static StringRELEASE_EXCEPTION_MESSAGEConstantRELEASE_EXCEPTION_MESSAGE="Not currently capturing"
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description LogbackRecordercapture(String level)Start capturing whatever is logged for this level of worse.static LogbackRecorderforClass(Class<?> clazz)Create 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 LogbackRecorderforName(String name)Create a recorder for a logback logger identified by its name.List<LogbackRecorder.Event>play()Return all recorded events.LogbackRecorderrelease()Stop recording and detach from the logger.LogbackRecorderreset()Resets the logger by clearing everything that was recorded so far.
-
-
-
Field Detail
-
DEFAULT_MUTE
public static final boolean DEFAULT_MUTE
ConstantDEFAULT_MUTE=true- See Also:
- Constant Field Values
-
DEFAULT_LEVEL
public static final String DEFAULT_LEVEL
ConstantDEFAULT_LEVEL="ALL"- See Also:
- Constant Field Values
-
LOGBACK_EXCEPTION_MESSAGE
public static final String LOGBACK_EXCEPTION_MESSAGE
ConstantLOGBACK_EXCEPTION_MESSAGE="Expected logback"- See Also:
- Constant Field Values
-
CAPTURE_EXCEPTION_MESSAGE
public static final String CAPTURE_EXCEPTION_MESSAGE
ConstantCAPTURE_EXCEPTION_MESSAGE="Already capturing"- See Also:
- Constant Field Values
-
RELEASE_EXCEPTION_MESSAGE
public static final String RELEASE_EXCEPTION_MESSAGE
ConstantRELEASE_EXCEPTION_MESSAGE="Not currently capturing"- See Also:
- Constant Field Values
-
-
Method Detail
-
forClass
public static final LogbackRecorder forClass(Class<?> clazz)
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
public static final LogbackRecorder forName(String name)
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
public static final LogbackRecorder forLogger(org.slf4j.Logger logger)
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
public LogbackRecorder reset()
Resets the logger by clearing everything that was recorded so far.- Returns:
- this
-
capture
public LogbackRecorder capture(String level)
Start capturing whatever is logged for this level of worse.- Parameters:
level- the level at which to start capturing- Returns:
- this
-
release
public LogbackRecorder release()
Stop recording and detach from the logger.- Returns:
- this
-
play
public List<LogbackRecorder.Event> play()
Return all recorded events.- Returns:
- all recorded events so far
-
-