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;
}
}
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();
}
Aggregations