use of org.apache.logging.log4j.core.config.LoggerConfig 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();
}
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project geode by apache.
the class Configurator method getLoggerConfig.
public static LoggerConfig getLoggerConfig(final String name) {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configuration config = context.getConfiguration();
LoggerConfig logConfig = config.getLoggerConfig(name);
if (!logConfig.getName().equals(name)) {
throw new IllegalStateException("LoggerConfig does not exist for " + name);
}
return logConfig;
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project geode by apache.
the class Configurator method setLevel.
public static void setLevel(String name, Level level) {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
LoggerConfig logConfig = getLoggerConfig(name);
logConfig.setLevel(level);
context.updateLoggers();
if (level.isLessSpecificThan(Level.DEBUG)) {
LogService.configureFastLoggerDelegating();
}
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project ignite by apache.
the class Log4J2Logger method createConsoleLogger.
/**
* Creates console appender with some reasonable default logging settings.
*
* @return Logger with auto configured console appender.
*/
public static Logger createConsoleLogger() {
LoggerContext ctx = (LoggerContext) LogManager.getContext(true);
Configuration cfg = ctx.getConfiguration();
PatternLayout.Builder builder = PatternLayout.newBuilder();
builder.withPattern("%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n").withCharset(Charset.defaultCharset()).withAlwaysWriteExceptions(false).withNoConsoleNoAnsi(false);
PatternLayout layout = builder.build();
ConsoleAppender.Builder consoleAppenderBuilder = ConsoleAppender.newBuilder();
consoleAppenderBuilder.withName(CONSOLE_APPENDER).withLayout(layout);
ConsoleAppender consoleApp = consoleAppenderBuilder.build();
consoleApp.start();
AppenderRef ref = AppenderRef.createAppenderRef(CONSOLE_APPENDER, Level.TRACE, null);
AppenderRef[] refs = { ref };
LoggerConfig logCfg = LoggerConfig.createLogger(false, Level.INFO, LogManager.ROOT_LOGGER_NAME, "", refs, null, null, null);
logCfg.addAppender(consoleApp, null, null);
cfg.addAppender(consoleApp);
cfg.addLogger(LogManager.ROOT_LOGGER_NAME, logCfg);
ctx.updateLoggers(cfg);
return (Logger) LogManager.getContext().getLogger(LogManager.ROOT_LOGGER_NAME);
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project logging-log4j2 by apache.
the class ConfigurationAssemblerTest method validate.
private void validate(final Configuration config) {
assertNotNull(config);
assertNotNull(config.getName());
assertFalse(config.getName().isEmpty());
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 2);
final KafkaAppender kafkaAppender = (KafkaAppender) appenders.get("Kafka");
final GelfLayout gelfLayout = (GelfLayout) kafkaAppender.getLayout();
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final LoggerConfig rootLoggerConfig = loggers.get("");
assertEquals(Level.ERROR, rootLoggerConfig.getLevel());
assertFalse(rootLoggerConfig.isIncludeLocation());
final LoggerConfig loggerConfig = loggers.get("org.apache.logging.log4j");
assertEquals(Level.DEBUG, loggerConfig.getLevel());
assertTrue(loggerConfig.isIncludeLocation());
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final List<CustomLevelConfig> customLevels = config.getCustomLevels();
assertNotNull("No CustomLevels", filter);
assertEquals(1, customLevels.size());
final CustomLevelConfig customLevel = customLevels.get(0);
assertEquals("Panic", customLevel.getLevelName());
assertEquals(17, customLevel.getIntLevel());
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
Aggregations