Search in sources :

Example 6 with ConsoleAppender

use of org.apache.logging.log4j.core.appender.ConsoleAppender 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)

Example 7 with ConsoleAppender

use of org.apache.logging.log4j.core.appender.ConsoleAppender in project logging-log4j2 by apache.

the class Log4j1ConfigurationFactoryTest method testConsole.

private Layout<?> testConsole(final String configResource) throws Exception {
    final Configuration configuration = getConfiguration(configResource);
    final String name = "Console";
    final ConsoleAppender appender = configuration.getAppender(name);
    assertNotNull("Missing appender '" + name + "' in configuration " + configResource + " → " + configuration, appender);
    assertEquals(Target.SYSTEM_ERR, appender.getTarget());
    //
    final LoggerConfig loggerConfig = configuration.getLoggerConfig("com.example.foo");
    assertNotNull(loggerConfig);
    assertEquals(Level.DEBUG, loggerConfig.getLevel());
    configuration.start();
    configuration.stop();
    return appender.getLayout();
}
Also used : ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) Configuration(org.apache.logging.log4j.core.config.Configuration) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Aggregations

ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)7 Appender (org.apache.logging.log4j.core.Appender)3 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)3 PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)3 IgniteLogger (org.apache.ignite.IgniteLogger)2 Logger (org.apache.logging.log4j.core.Logger)2 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)2 AppenderRef (org.apache.logging.log4j.core.config.AppenderRef)2 Configuration (org.apache.logging.log4j.core.config.Configuration)2 Test (org.junit.Test)2 PerfLogger (org.apache.hadoop.hive.ql.log.PerfLogger)1 Logger (org.apache.logging.log4j.Logger)1 Layout (org.apache.logging.log4j.core.Layout)1 AbstractOutputStreamAppender (org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender)1 RollingFileAppender (org.apache.logging.log4j.core.appender.RollingFileAppender)1 RoutingAppender (org.apache.logging.log4j.core.appender.routing.RoutingAppender)1 AbstractConfiguration (org.apache.logging.log4j.core.config.AbstractConfiguration)1 CompositeConfiguration (org.apache.logging.log4j.core.config.composite.CompositeConfiguration)1 LoggerContextRule (org.apache.logging.log4j.junit.LoggerContextRule)1