[TEST] Reset test logger to default level

This commit is contained in:
Simon Willnauer 2014-12-10 22:47:03 +01:00
parent 633905161a
commit 788d7cb451
1 changed files with 24 additions and 17 deletions

View File

@ -22,11 +22,13 @@ package org.elasticsearch.common.logging.log4j;
import org.apache.log4j.Appender;
import org.apache.log4j.Logger;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -51,26 +53,31 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase {
@Test
public void testResolveMultipleConfigs() throws Exception {
Path configDir = resolveConfigDir();
Settings settings = ImmutableSettings.builder()
.put("path.conf", configDir.toAbsolutePath())
.build();
LogConfigurator.configure(settings);
String level = Log4jESLoggerFactory.getLogger("test").getLevel();
try {
Path configDir = resolveConfigDir();
Settings settings = ImmutableSettings.builder()
.put("path.conf", configDir.toAbsolutePath())
.build();
LogConfigurator.configure(settings);
ESLogger esLogger = Log4jESLoggerFactory.getLogger("test");
Logger logger = ((Log4jESLogger) esLogger).logger();
Appender appender = logger.getAppender("console");
assertThat(appender, notNullValue());
ESLogger esLogger = Log4jESLoggerFactory.getLogger("test");
Logger logger = ((Log4jESLogger) esLogger).logger();
Appender appender = logger.getAppender("console");
assertThat(appender, notNullValue());
esLogger = Log4jESLoggerFactory.getLogger("second");
logger = ((Log4jESLogger) esLogger).logger();
appender = logger.getAppender("console2");
assertThat(appender, notNullValue());
esLogger = Log4jESLoggerFactory.getLogger("second");
logger = ((Log4jESLogger) esLogger).logger();
appender = logger.getAppender("console2");
assertThat(appender, notNullValue());
esLogger = Log4jESLoggerFactory.getLogger("third");
logger = ((Log4jESLogger) esLogger).logger();
appender = logger.getAppender("console3");
assertThat(appender, notNullValue());
esLogger = Log4jESLoggerFactory.getLogger("third");
logger = ((Log4jESLogger) esLogger).logger();
appender = logger.getAppender("console3");
assertThat(appender, notNullValue());
} finally {
Log4jESLoggerFactory.getLogger("test").setLevel(level);
}
}
@Test