Class ProcessEngineLoggingExtension

java.lang.Object
org.operaton.bpm.engine.test.junit5.ProcessEngineLoggingExtension
All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterTestExecutionCallback, org.junit.jupiter.api.extension.BeforeTestExecutionCallback, org.junit.jupiter.api.extension.Extension

public class ProcessEngineLoggingExtension extends Object implements org.junit.jupiter.api.extension.BeforeTestExecutionCallback, org.junit.jupiter.api.extension.AfterTestExecutionCallback
JUnit 5 Extension to monitor and capture log events for specified loggers during test execution.

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:

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 Details

  • Constructor Details

    • ProcessEngineLoggingExtension

      public ProcessEngineLoggingExtension()
  • Method Details

    • watch

      public ProcessEngineLoggingExtension watch(String... loggerName)
    • watch

      public ProcessEngineLoggingExtension watch(String loggerName, ch.qos.logback.classic.Level level)
    • level

      public ProcessEngineLoggingExtension level(ch.qos.logback.classic.Level level)
    • getLog

      public List<ch.qos.logback.classic.spi.ILoggingEvent> getLog(String loggerName)
    • getLog

      public List<ch.qos.logback.classic.spi.ILoggingEvent> getLog()
    • getFilteredLog

      public List<ch.qos.logback.classic.spi.ILoggingEvent> getFilteredLog(String subString)
    • getFilteredLog

      public List<ch.qos.logback.classic.spi.ILoggingEvent> getFilteredLog(String loggerName, String subString)
    • beforeTestExecution

      public void beforeTestExecution(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      beforeTestExecution in interface org.junit.jupiter.api.extension.BeforeTestExecutionCallback
    • afterTestExecution

      public void afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext context)
      Specified by:
      afterTestExecution in interface org.junit.jupiter.api.extension.AfterTestExecutionCallback