Verisoft Wiki

LogsExtension is a JUnit 5 Extension responsible for initializing and managing the logging system during test execution.

It is based on Slf4jObserver and ensures that every report message (ReportEntry) is handled according to its source and log level.


How it works

The extension initializes Slf4jObserver, which receives Report messages and logs them to SLF4J according to the configuration:


Logging configuration with logback-test.xml

The logback-test.xml file allows you to customize the logging output for your tests. Using this file, you can:

This file is automatically picked up by the Logback framework during test execution, allowing you to experiment with different logging configurations without modifying your code.

For more details and examples, see the Baeldung guide on Logback.


Managing ReportSource

Call Behavior
ReportSource.REPORT Not logged to SLF4J (intended for report observers only)
ReportSource.LOG Logged only to SLF4J
ReportSource.OTHER Logs to all targets (SLF4J and the other report observers)

Usage examples

@ExtendWith(LogsExtension.class)
public class MyTest {
    @Test
    public void logTest(){
        Report.info("report massage"); 
        // Logged to all report observers at INFO level
        
        Report.report(ReportSource.REPORT, ReportLevel.DEBUG, "report massage");
        // Not logged to SLF4J
        
        Report.report(ReportSource.LOG, ReportLevel.DEBUG, "report massage"); 
        // Logged to SLF4J at DEBUG level
    }
}