Search in sources :

Example 1 with AppenderContext

use of org.apache.geode.internal.logging.log4j.AppenderContext in project geode by apache.

the class LogService method removeConsoleAppender.

/**
   * Removes STDOUT ConsoleAppender from ROOT logger. Only called when using the log4j2-default.xml
   * configuration. This is done when creating the LogWriterAppender for log-file. The Appender
   * instance is stored in stdoutAppender so it can be restored later using restoreConsoleAppender.
   */
public static synchronized void removeConsoleAppender() {
    final AppenderContext appenderContext = LogService.getAppenderContext(LogService.ROOT_LOGGER_NAME);
    final LoggerConfig config = appenderContext.getLoggerConfig();
    Appender stdout = config.getAppenders().get(STDOUT);
    if (stdout != null) {
        config.removeAppender(STDOUT);
        stdoutAppender = stdout;
        appenderContext.getLoggerContext().updateLoggers();
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) AppenderContext(org.apache.geode.internal.logging.log4j.AppenderContext) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 2 with AppenderContext

use of org.apache.geode.internal.logging.log4j.AppenderContext in project geode by apache.

the class LogService method restoreConsoleAppender.

/**
   * Restores STDOUT ConsoleAppender to ROOT logger. Only called when using the log4j2-default.xml
   * configuration. This is done when the LogWriterAppender for log-file is destroyed. The Appender
   * instance stored in stdoutAppender is used.
   */
public static synchronized void restoreConsoleAppender() {
    if (stdoutAppender == null) {
        return;
    }
    final AppenderContext appenderContext = LogService.getAppenderContext(LogService.ROOT_LOGGER_NAME);
    final LoggerConfig config = appenderContext.getLoggerConfig();
    Appender stdout = config.getAppenders().get(STDOUT);
    if (stdout == null) {
        config.addAppender(stdoutAppender, Level.ALL, null);
        appenderContext.getLoggerContext().updateLoggers();
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) AppenderContext(org.apache.geode.internal.logging.log4j.AppenderContext) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 3 with AppenderContext

use of org.apache.geode.internal.logging.log4j.AppenderContext in project geode by apache.

the class LogServiceJUnitTest method getAppenderContextWithNameShouldHaveName.

@Test
public void getAppenderContextWithNameShouldHaveName() throws Exception {
    final String name = "someName";
    final AppenderContext appenderContext = LogService.getAppenderContext(name);
    assertThat(appenderContext.getName()).isEqualTo(name);
}
Also used : AppenderContext(org.apache.geode.internal.logging.log4j.AppenderContext) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 4 with AppenderContext

use of org.apache.geode.internal.logging.log4j.AppenderContext in project geode by apache.

the class LogServiceJUnitTest method getAppenderContextShouldHaveEmptyName.

@Test
public void getAppenderContextShouldHaveEmptyName() throws Exception {
    final AppenderContext appenderContext = LogService.getAppenderContext();
    assertThat(appenderContext.getName()).isEmpty();
}
Also used : AppenderContext(org.apache.geode.internal.logging.log4j.AppenderContext) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Aggregations

AppenderContext (org.apache.geode.internal.logging.log4j.AppenderContext)4 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2 Appender (org.apache.logging.log4j.core.Appender)2 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)2 Test (org.junit.Test)2