Skip to content

Commit

Permalink
[TEST] Reset test logger to default level
Browse files Browse the repository at this point in the history
  • Loading branch information
s1monw committed Dec 10, 2014
1 parent 63573a9 commit 9e6d6b3
Showing 1 changed file with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
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;

Expand All @@ -50,26 +52,31 @@ public void before() throws Exception {

@Test
public void testResolveMultipleConfigs() throws Exception {
File configDir = resolveConfigDir();
Settings settings = ImmutableSettings.builder()
.put("path.conf", configDir.getAbsolutePath())
.build();
LogConfigurator.configure(settings);

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("third");
logger = ((Log4jESLogger) esLogger).logger();
appender = logger.getAppender("console3");
assertThat(appender, notNullValue());
String level = Log4jESLoggerFactory.getLogger("test").getLevel();
try {
File configDir = resolveConfigDir();
Settings settings = ImmutableSettings.builder()
.put("path.conf", configDir.getAbsolutePath())
.build();
LogConfigurator.configure(settings);

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("third");
logger = ((Log4jESLogger) esLogger).logger();
appender = logger.getAppender("console3");
assertThat(appender, notNullValue());
} finally {
Log4jESLoggerFactory.getLogger("test").setLevel(level);
}
}

@Test
Expand Down

0 comments on commit 9e6d6b3

Please sign in to comment.