Skip to content

Commit

Permalink
[netceteragroup#98] Reset logger context to ensure that no appenders …
Browse files Browse the repository at this point in the history
…are present in the Logback's logger tree

* Currently, the ROOT logger has a ConsoleAppender attached, which introduces side effects affecting the RetainingAppender tests
  • Loading branch information
Darko Filipovski authored and Darko Filipovski committed Sep 4, 2024
1 parent 8b48e41 commit 0378107
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class RetainingAppenderTest {
@BeforeEach
void init() {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
// Resetting the context is necessary because Logback's BasicConfigurator initializes a ConsoleAppender which
// introduces unexpected side effects.
context.reset();

// loggers
ch.qos.logback.classic.Logger logger = context.getLogger(TEST_APPENDER_NAME);
Expand Down Expand Up @@ -85,10 +88,6 @@ void shouldRetainDebugAndTraceEvents() {
assertThat(appenderContent, not(containsString("DEBUG" + suffix)));
}

private String getBufferAppenderContent() {
return bufferingAppender.dumpCsv();
}

@Test
void shouldDumpDebugEventOnceErrorOccurred() {
// given testLogger setup plus...
Expand All @@ -115,7 +114,7 @@ void shouldDumpDebugEventOnceErrorOccurred() {
}

@Test
void shouldSupportAppenderAttacheableMethods() {
void shouldSupportAppenderAttachableMethods() {
RetainingAppender retainingAppender = new RetainingAppender();
assertThat(retainingAppender.iteratorForAppenders().hasNext(), is(false));
assertThat(retainingAppender.isAttached(bufferingAppender), is(false));
Expand Down Expand Up @@ -152,4 +151,8 @@ void shouldSupportAppenderAttacheableMethods() {
assertThat(retainingAppender.getAppender(TEST_APPENDER_NAME), is(nullValue()));
}

private String getBufferAppenderContent() {
return bufferingAppender.dumpCsv();
}

}

0 comments on commit 0378107

Please sign in to comment.