Package nva.commons.logutils
Class LogRecorder
java.lang.Object
nva.commons.logutils.LogRecorder
Records log events emitted during a test. Unlike
LogUtils, this helper does not
reconfigure the Log4j context: it attaches a ListAppender to either a single class logger
or the root logger, leaving the rest of the configuration untouched.-
Method Summary
Modifier and TypeMethodDescriptionasString()Space-joined rendering of all captured messages.voidclear()Discard all captured events.List<org.apache.logging.log4j.core.LogEvent> events()All captured log events, in the order they were emitted.static LogRecorderStart a recorder on the logger for the given class.static LogRecorderStart a recorder on the root logger.messages()Formatted messages of all captured events, in the order they were emitted.
-
Method Details
-
forClass
Start a recorder on the logger for the given class. The returned recorder is empty: any previously captured events on the same logger are discarded. Tests that share a recorder across methods (for example, obtained once in@BeforeAll) should callclear()themselves between tests.- Parameters:
clazz- the class whose logger should be captured.
-
forRoot
Start a recorder on the root logger. The returned recorder is empty: any previously captured events on the root logger are discarded. Thecallerclass is used to resolve the correctLoggerContext; pass the test class itself.- Parameters:
caller- the test class invoking this helper, used to resolve the right LoggerContext.
-
messages
Formatted messages of all captured events, in the order they were emitted. -
events
All captured log events, in the order they were emitted. -
asString
Space-joined rendering of all captured messages. Thrown exception messages are appended. -
clear
public void clear()Discard all captured events.
-