Skip to content

io microsphere logging test jupiter extension logging LoggingLevelCallback

github-actions[bot] edited this page May 30, 2026 · 9 revisions

LoggingLevelCallback

Type: Class | Module: microsphere-logging-test | Package: io.microsphere.logging.test.jupiter.extension.logging | Since: 1.0.0

Source: microsphere-logging-test/src/main/java/io/microsphere/logging/test/jupiter/extension/logging/LoggingLevelCallback.java

Overview

The Callback to set logging level before test method and recover it after test method.

Declaration

class LoggingLevelCallback implements BeforeEachCallback, AfterEachCallback

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.14-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

Method Examples

beforeEach

List<Logging> loggings = LoggingUtils.loadAll();
  LoggingLevelCallback callback = new LoggingLevelCallback(loggings, new String[]{"io.microsphere"}, "DEBUG");
// Called automatically by JUnit 5 before each test method in a @LoggingLevelsTest template
  callback.beforeEach(extensionContext);

afterEach

// Called automatically by JUnit 5 after each test method in a @LoggingLevelsTest template
  callback.afterEach(extensionContext);

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-logging-test</artifactId>
    <version>${microsphere-logging.version}</version>
</dependency>

Tip: Use the BOM (microsphere-logging-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.logging.test.jupiter.extension.logging.LoggingLevelCallback;

API Reference

Public Methods

Method Description
beforeEach Creates a new LoggingLevelCallback.
afterEach Restores the original logging levels for each logger name after each test method completes.

Method Details

beforeEach

public void beforeEach(ExtensionContext context)

Creates a new LoggingLevelCallback.

Example Usage

`List loggings = LoggingUtils.loadAll();
  LoggingLevelCallback callback = new LoggingLevelCallback(loggings, new String[]{"io.microsphere"`, "DEBUG");
}

afterEach

public void afterEach(ExtensionContext context)

Restores the original logging levels for each logger name after each test method completes.

Example Usage

`// Called automatically by JUnit 5 after each test method in a @LoggingLevelsTest template
  callback.afterEach(extensionContext);
`

See Also

  • BeforeEachCallback
  • AfterEachCallback

This documentation was auto-generated from the source code of microsphere-logging.

Clone this wiki locally