Search in sources :

Example 16 with Logger

use of org.apache.logging.log4j.core.Logger in project torodb by torodb.

the class Log4jUtils method addRootAppenderListener.

public static void addRootAppenderListener(AppenderListener appenderListener) {
    org.apache.logging.log4j.Logger logger = org.apache.logging.log4j.LogManager.getRootLogger();
    org.apache.logging.log4j.core.Logger coreLogger = (org.apache.logging.log4j.core.Logger) logger;
    InternalAppenderListener internalAppenderListener = new InternalAppenderListener(appenderListener);
    internalAppenderListener.start();
    coreLogger.addAppender(internalAppenderListener);
}
Also used : Logger(org.apache.logging.log4j.core.Logger) Logger(org.apache.logging.log4j.core.Logger)

Example 17 with Logger

use of org.apache.logging.log4j.core.Logger in project geode by apache.

the class AppenderContext method getLoggerConfig.

public LoggerConfig getLoggerConfig() {
    final Logger logger = getLogger();
    final LoggerContext context = logger.getContext();
    return context.getConfiguration().getLoggerConfig(logger.getName());
}
Also used : Logger(org.apache.logging.log4j.core.Logger) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 18 with Logger

use of org.apache.logging.log4j.core.Logger in project geode by apache.

the class LogServiceIntegrationJUnitTest method removeConsoleAppenderShouldRemoveStdout.

@Test
public void removeConsoleAppenderShouldRemoveStdout() {
    LogService.reconfigure();
    final Logger rootLogger = (Logger) LogService.getRootLogger();
    LogService.removeConsoleAppender();
    assertThat(rootLogger.getAppenders().get(LogService.STDOUT)).isNull();
}
Also used : StatusLogger(org.apache.logging.log4j.status.StatusLogger) Logger(org.apache.logging.log4j.core.Logger) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 19 with Logger

use of org.apache.logging.log4j.core.Logger in project geode by apache.

the class LogServiceIntegrationJUnitTest method restoreConsoleAppenderShouldRestoreStdout.

@Test
public void restoreConsoleAppenderShouldRestoreStdout() {
    LogService.reconfigure();
    final Logger rootLogger = (Logger) LogService.getRootLogger();
    LogService.removeConsoleAppender();
    assertThat(rootLogger.getAppenders().get(LogService.STDOUT)).isNull();
    LogService.restoreConsoleAppender();
    assertThat(rootLogger.getAppenders().get(LogService.STDOUT)).isNotNull();
}
Also used : StatusLogger(org.apache.logging.log4j.status.StatusLogger) Logger(org.apache.logging.log4j.core.Logger) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 20 with Logger

use of org.apache.logging.log4j.core.Logger in project ignite by apache.

the class Log4J2Logger method addConsoleAppenderIfNeeded.

/**
     * Adds console appender when needed with some default logging settings.
     *
     * @param initLogClo Optional log implementation init closure.
     */
private void addConsoleAppenderIfNeeded(@Nullable IgniteClosure<Boolean, Logger> initLogClo) {
    if (inited) {
        // Do not init.
        impl = initLogClo.apply(false);
        return;
    }
    synchronized (mux) {
        if (inited) {
            // Do not init.
            impl = initLogClo.apply(false);
            return;
        }
        // Init logger impl.
        impl = initLogClo.apply(true);
        boolean quiet = Boolean.valueOf(System.getProperty(IGNITE_QUIET, "true"));
        boolean consoleAppenderFound = false;
        Logger rootLogger = null;
        for (Logger log = impl; log != null; ) {
            if (!consoleAppenderFound) {
                for (Appender appender : log.getAppenders().values()) {
                    if (appender instanceof ConsoleAppender) {
                        if ("CONSOLE_ERR".equals(appender.getName()))
                            continue;
                        consoleAppenderFound = true;
                        break;
                    }
                }
            }
            if (log.getParent() == null) {
                rootLogger = log;
                break;
            } else
                log = log.getParent();
        }
        if (consoleAppenderFound && quiet)
            // User configured console appender, but log is quiet.
            quiet = false;
        if (!consoleAppenderFound && !quiet && Boolean.valueOf(System.getProperty(IGNITE_CONSOLE_APPENDER, "true"))) {
            // Console appender not found => we've looked through all categories up to root.
            assert rootLogger != null;
            // User launched ignite in verbose mode and did not add console appender with INFO level
            // to configuration and did not set IGNITE_CONSOLE_APPENDER to false.
            consoleLog = createConsoleLogger();
        }
        quiet0 = quiet;
        inited = true;
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) RoutingAppender(org.apache.logging.log4j.core.appender.routing.RoutingAppender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) IgniteLogger(org.apache.ignite.IgniteLogger) Logger(org.apache.logging.log4j.core.Logger)

Aggregations

Logger (org.apache.logging.log4j.core.Logger)34 Test (org.junit.Test)20 LoggerContext (org.apache.logging.log4j.core.LoggerContext)6 Appender (org.apache.logging.log4j.core.Appender)5 StatusLogger (org.apache.logging.log4j.status.StatusLogger)5 Field (java.lang.reflect.Field)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 Marker (org.apache.logging.log4j.Marker)4 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)4 IgniteLogger (org.apache.ignite.IgniteLogger)3 LogEvent (org.apache.logging.log4j.core.LogEvent)3 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)3 List (java.util.List)2 Map (java.util.Map)2 ExecutorService (java.util.concurrent.ExecutorService)2 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)2 RollingFileAppender (org.apache.logging.log4j.core.appender.RollingFileAppender)2 RoutingAppender (org.apache.logging.log4j.core.appender.routing.RoutingAppender)2 Log4jLogger (org.apache.logging.slf4j.Log4jLogger)2 LogLevel (com.torodb.packaging.config.model.generic.LogLevel)1