Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a Jupiter extension that will automagically reset the Logback logging system #461

Closed
sleberknight opened this issue Feb 6, 2024 · 0 comments · Fixed by #468
Closed
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

sleberknight commented Feb 6, 2024

Note that this depends on completion of #460

From a comment in #457:

In addition, we could also create a Jupiter extension that would automagically reset the Logback logging system assuming the default logback-test.xml (and maybe if that isn't found it falls back to logback.xml. For example:

@ExtendWith(ResetLogbackLoggingExtension.class)
class MyTest {
    // ...
}

And if there is a need to customize the logging configuration, then it could be registered programmatically:

class MyTest {

    @RegisterExtension
    static final ResetLogbackLoggingExtension resetLogbackExtension =
            ResetLogbackLoggingExtension.builder()
                .withLoggingConfiguration("my-custom-test-logback-config.xml")
                .build()
    // ...
}

The extension would reset Logback after all tests have run, e.g. in a @AfterAll.

Originally posted by @sleberknight in #457 (comment)

@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label Feb 6, 2024
@sleberknight sleberknight added this to the 3.3.0 milestone Feb 9, 2024
sleberknight added a commit that referenced this issue Feb 9, 2024
* Add LogbackTestHelpers utility class. This provides utilities
  to reset Logback.
* Add ResetLogbackLoggingExtension, a Jupiter extension to
   reset Logback after all tests have run.
* Add UncheckedJoranException, which wraps the checked
  Logback JoranException.
* Update several tests that use Dropwizard extensions to use
   ResetLogbackLoggingExtension to restore logging.

Closes #460
Closes #461
sleberknight added a commit that referenced this issue Feb 10, 2024
* Add LogbackTestHelpers utility class. This provides static
   utilities to reset Logback.
* Add LogbackTestHelper which mainly delegates to LogbackTestHelpers.
  It adds a new method, resetLogbackWithDefaultOrConfig, which removes
  the duplicate conditional logic in the InMemoryAppenderExtension and
  the ResetLogbackLoggingExtension. It also allows for mocking in
  tests of the Logback reset mechanisms and extensions.
* Add ResetLogbackLoggingExtension, a Jupiter extension to
   reset Logback after all tests have run.
* Add UncheckedJoranException, which wraps the checked
  Logback JoranException.
* Update several tests that use Dropwizard extensions to use
   ResetLogbackLoggingExtension to restore logging.
* Replace duplicate code in InMemoryAppenderExtension with
  call to LogbackTestHelpers#resetLogback

Misc cleanup:

* Make visibility of Dropwizard Configuration classes in
  several tests the same as the Application class
* Add test for InMemoryAppenderExtension.
* Add "clear-box" tests for InMemoryAppenderExtension#getAppender

Closes #460
Closes #461
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant