use of org.apache.logging.log4j.core.config.Configuration in project elasticsearch by elastic.
the class EvilLoggerConfigurationTests method testResolveMultipleConfigs.
public void testResolveMultipleConfigs() throws Exception {
final Level level = ESLoggerFactory.getLogger("test").getLevel();
try {
final Path configDir = getDataPath("config");
final Settings settings = Settings.builder().put(Environment.PATH_CONF_SETTING.getKey(), configDir.toAbsolutePath()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
final Environment environment = new Environment(settings);
LogConfigurator.configure(environment);
{
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig("test");
final Appender appender = loggerConfig.getAppenders().get("console");
assertThat(appender, notNullValue());
}
{
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig("second");
final Appender appender = loggerConfig.getAppenders().get("console2");
assertThat(appender, notNullValue());
}
{
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig("third");
final Appender appender = loggerConfig.getAppenders().get("console3");
assertThat(appender, notNullValue());
}
} finally {
Configurator.setLevel("test", level);
}
}
use of org.apache.logging.log4j.core.config.Configuration in project camel by apache.
the class ConsumingAppender method newAppender.
public static Appender newAppender(String loggerName, String appenderName, String patter, Level level, Consumer<LogEvent> consumer) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
config.removeLogger(loggerName);
ConsumingAppender appender = new ConsumingAppender(appenderName, patter, consumer);
appender.start();
LoggerConfig loggerConfig = LoggerConfig.createLogger(true, level, loggerName, "true", new AppenderRef[] { AppenderRef.createAppenderRef(appenderName, null, null) }, null, config, null);
loggerConfig.addAppender(appender, null, null);
config.addLogger(loggerName, loggerConfig);
ctx.updateLoggers();
return appender;
}
use of org.apache.logging.log4j.core.config.Configuration in project spring-boot by spring-projects.
the class Log4J2LoggingSystemTests method withFile.
@Test
public void withFile() throws Exception {
this.loggingSystem.beforeInitialize();
this.logger.info("Hidden");
this.loggingSystem.initialize(null, null, getLogFile(null, tmpDir()));
this.logger.info("Hello world");
String output = this.output.toString().trim();
Configuration configuration = this.loggingSystem.getConfiguration();
assertThat(output).contains("Hello world").doesNotContain("Hidden");
assertThat(new File(tmpDir() + "/spring.log").exists()).isTrue();
assertThat(configuration.getConfigurationSource().getFile()).isNotNull();
}
use of org.apache.logging.log4j.core.config.Configuration in project spring-boot by spring-projects.
the class Log4J2LoggingSystemTests method testNonDefaultConfigLocation.
@Test
public void testNonDefaultConfigLocation() throws Exception {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(null, "classpath:log4j2-nondefault.xml", getLogFile(tmpDir() + "/tmp.log", null));
this.logger.info("Hello world");
String output = this.output.toString().trim();
Configuration configuration = this.loggingSystem.getConfiguration();
assertThat(output).contains("Hello world").contains(tmpDir() + "/tmp.log");
assertThat(new File(tmpDir() + "/tmp.log").exists()).isFalse();
assertThat(configuration.getConfigurationSource().getFile().getAbsolutePath()).contains("log4j2-nondefault.xml");
assertThat(configuration.getWatchManager().getIntervalSeconds()).isEqualTo(30);
}
use of org.apache.logging.log4j.core.config.Configuration in project graylog2-server by Graylog2.
the class LoggersResource method getLoggerConfigs.
@VisibleForTesting
protected Collection<LoggerConfig> getLoggerConfigs() {
final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
final Configuration configuration = loggerContext.getConfiguration();
return configuration.getLoggers().values();
}
Aggregations