[TEST] Reset test logger to default level
This commit is contained in:
parent
633905161a
commit
788d7cb451
|
@ -22,11 +22,13 @@ package org.elasticsearch.common.logging.log4j;
|
||||||
import org.apache.log4j.Appender;
|
import org.apache.log4j.Appender;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
import org.elasticsearch.common.logging.ESLogger;
|
||||||
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.env.Environment;
|
import org.elasticsearch.env.Environment;
|
||||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -51,26 +53,31 @@ public class LoggingConfigurationTests extends ElasticsearchTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResolveMultipleConfigs() throws Exception {
|
public void testResolveMultipleConfigs() throws Exception {
|
||||||
Path configDir = resolveConfigDir();
|
String level = Log4jESLoggerFactory.getLogger("test").getLevel();
|
||||||
Settings settings = ImmutableSettings.builder()
|
try {
|
||||||
.put("path.conf", configDir.toAbsolutePath())
|
Path configDir = resolveConfigDir();
|
||||||
.build();
|
Settings settings = ImmutableSettings.builder()
|
||||||
LogConfigurator.configure(settings);
|
.put("path.conf", configDir.toAbsolutePath())
|
||||||
|
.build();
|
||||||
|
LogConfigurator.configure(settings);
|
||||||
|
|
||||||
ESLogger esLogger = Log4jESLoggerFactory.getLogger("test");
|
ESLogger esLogger = Log4jESLoggerFactory.getLogger("test");
|
||||||
Logger logger = ((Log4jESLogger) esLogger).logger();
|
Logger logger = ((Log4jESLogger) esLogger).logger();
|
||||||
Appender appender = logger.getAppender("console");
|
Appender appender = logger.getAppender("console");
|
||||||
assertThat(appender, notNullValue());
|
assertThat(appender, notNullValue());
|
||||||
|
|
||||||
esLogger = Log4jESLoggerFactory.getLogger("second");
|
esLogger = Log4jESLoggerFactory.getLogger("second");
|
||||||
logger = ((Log4jESLogger) esLogger).logger();
|
logger = ((Log4jESLogger) esLogger).logger();
|
||||||
appender = logger.getAppender("console2");
|
appender = logger.getAppender("console2");
|
||||||
assertThat(appender, notNullValue());
|
assertThat(appender, notNullValue());
|
||||||
|
|
||||||
esLogger = Log4jESLoggerFactory.getLogger("third");
|
esLogger = Log4jESLoggerFactory.getLogger("third");
|
||||||
logger = ((Log4jESLogger) esLogger).logger();
|
logger = ((Log4jESLogger) esLogger).logger();
|
||||||
appender = logger.getAppender("console3");
|
appender = logger.getAppender("console3");
|
||||||
assertThat(appender, notNullValue());
|
assertThat(appender, notNullValue());
|
||||||
|
} finally {
|
||||||
|
Log4jESLoggerFactory.getLogger("test").setLevel(level);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue