Search in sources :

Example 1 with LoggerContextListener

use of ch.qos.logback.classic.spi.LoggerContextListener in project sonarqube by SonarSource.

the class LogbackHelperTest method enableJulChangePropagation.

@Test
public void enableJulChangePropagation() {
    LoggerContext ctx = underTest.getRootContext();
    int countListeners = ctx.getCopyOfListenerList().size();
    LoggerContextListener propagator = underTest.enableJulChangePropagation(ctx);
    assertThat(ctx.getCopyOfListenerList().size()).isEqualTo(countListeners + 1);
    ctx.removeListener(propagator);
}
Also used : LoggerContextListener(ch.qos.logback.classic.spi.LoggerContextListener) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 2 with LoggerContextListener

use of ch.qos.logback.classic.spi.LoggerContextListener in project spring-boot by spring-projects.

the class LogbackLoggingSystemTests method initializationIsOnlyPerformedOnceUntilCleanedUp.

@Test
public void initializationIsOnlyPerformedOnceUntilCleanedUp() throws Exception {
    LoggerContext loggerContext = (LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory();
    LoggerContextListener listener = mock(LoggerContextListener.class);
    loggerContext.addListener(listener);
    this.loggingSystem.beforeInitialize();
    this.loggingSystem.initialize(this.initializationContext, null, null);
    this.loggingSystem.beforeInitialize();
    this.loggingSystem.initialize(this.initializationContext, null, null);
    verify(listener, times(1)).onReset(loggerContext);
    this.loggingSystem.cleanUp();
    loggerContext.addListener(listener);
    this.loggingSystem.beforeInitialize();
    this.loggingSystem.initialize(this.initializationContext, null, null);
    verify(listener, times(2)).onReset(loggerContext);
}
Also used : LoggerContextListener(ch.qos.logback.classic.spi.LoggerContextListener) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Aggregations

LoggerContext (ch.qos.logback.classic.LoggerContext)2 LoggerContextListener (ch.qos.logback.classic.spi.LoggerContextListener)2 Test (org.junit.Test)2