Class ProcessEngineLoggingExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterTestExecutionCallback,org.junit.jupiter.api.extension.BeforeTestExecutionCallback,org.junit.jupiter.api.extension.Extension
This extension provides the capability to watch specific loggers at a customizable log level.
By default, all watched loggers are set to DEBUG level unless specified otherwise.
Usage:
@RegisterExtension
ProcessEngineLoggingExtension loggingExtension = new ProcessEngineLoggingExtension()
.watch("org.operaton.bpm.engine")
.level(Level.INFO);
During test execution, this extension intercepts log events for specified loggers and stores them,
allowing the logs to be accessed and filtered based on test-specific criteria.
For example, calling getLog(String) provides a list of log events for a specific logger.
You may also filter log entries containing a particular substring by using
getFilteredLog(String, String).
Methods:
watch(String...)- Starts watching specified loggers with the default or specified log level.level(Level)- Sets the global log level for all watched loggers.getLog(String)- Retrieves the log entries recorded for a specified logger.getFilteredLog(String, String)- Retrieves log entries containing a specified substring.
Logging Flow:
Before each test execution, the extension attaches an in-memory appender to each watched logger. After the test execution, the extension detaches all appenders, restoring original log configurations. This ensures no residual configuration persists beyond the test's scope.
Example usage with filtered logs:
List<ILoggingEvent> filteredLogs = loggingExtension.getFilteredLog("org.operaton.bpm.engine", "error message");
The extension is especially useful in scenarios where log messages play a key role in testing, such as verifying that certain events are logged at specific levels.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterTestExecution(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeTestExecution(org.junit.jupiter.api.extension.ExtensionContext context) List<ch.qos.logback.classic.spi.ILoggingEvent> getFilteredLog(String subString) List<ch.qos.logback.classic.spi.ILoggingEvent> getFilteredLog(String loggerName, String subString) List<ch.qos.logback.classic.spi.ILoggingEvent> getLog()List<ch.qos.logback.classic.spi.ILoggingEvent> level(ch.qos.logback.classic.Level level)
-
Field Details
-
LOGGER_NOT_FOUND_ERROR
- See Also:
-
NOT_WATCHING_ERROR
- See Also:
-
-
Constructor Details
-
ProcessEngineLoggingExtension
public ProcessEngineLoggingExtension()
-
-
Method Details
-
watch
-
watch
-
level
-
getLog
-
getLog
-
getFilteredLog
-
getFilteredLog
-
beforeTestExecution
public void beforeTestExecution(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
beforeTestExecutionin interfaceorg.junit.jupiter.api.extension.BeforeTestExecutionCallback
-
afterTestExecution
public void afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext context) - Specified by:
afterTestExecutionin interfaceorg.junit.jupiter.api.extension.AfterTestExecutionCallback
-