use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class EvilLoggerConfigurationTests method testHierarchy.
public void testHierarchy() throws Exception {
final Path configDir = getDataPath("hierarchy");
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);
assertThat(ESLoggerFactory.getLogger("x").getLevel(), equalTo(Level.TRACE));
assertThat(ESLoggerFactory.getLogger("x.y").getLevel(), equalTo(Level.DEBUG));
final Level level = randomFrom(Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR);
Loggers.setLevel(ESLoggerFactory.getLogger("x"), level);
assertThat(ESLoggerFactory.getLogger("x").getLevel(), equalTo(level));
assertThat(ESLoggerFactory.getLogger("x.y").getLevel(), equalTo(level));
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class EvilLoggerConfigurationTests method testDefaults.
public void testDefaults() throws IOException, UserException {
final Path configDir = getDataPath("config");
final String level = randomFrom(Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR).toString();
final Settings settings = Settings.builder().put(Environment.PATH_CONF_SETTING.getKey(), configDir.toAbsolutePath()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put("logger.level", level).build();
final Environment environment = new Environment(settings);
LogConfigurator.configure(environment);
final String loggerName = "test";
final Logger logger = ESLoggerFactory.getLogger(loggerName);
assertThat(logger.getLevel().toString(), equalTo(level));
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class EvilLoggerConfigurationTests method testResolveOrder.
// tests that custom settings are not overwritten by settings in the config file
public void testResolveOrder() throws Exception {
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()).put("logger.test_resolve_order", "TRACE").build();
final Environment environment = new Environment(settings);
LogConfigurator.configure(environment);
// args should overwrite whatever is in the config
final String loggerName = "test_resolve_order";
final Logger logger = ESLoggerFactory.getLogger(loggerName);
assertTrue(logger.isTraceEnabled());
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class EvilLoggerConfigurationTests method testMissingConfigFile.
public void testMissingConfigFile() {
final Path configDir = getDataPath("does_not_exist");
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);
UserException e = expectThrows(UserException.class, () -> LogConfigurator.configure(environment));
assertThat(e, hasToString(containsString("no log4j2.properties found; tried")));
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class InstallPluginCommandTests method installPlugin.
private void installPlugin(MockTerminal terminal, boolean isBatch) throws Exception {
Tuple<Path, Environment> env = createEnv(fs, temp);
Path pluginDir = createPluginDir(temp);
// if batch is enabled, we also want to add a security policy
String pluginZip = createPlugin("fake", pluginDir, isBatch);
new InstallPluginCommand() {
@Override
void jarHellCheck(Path candidate, Path pluginsDir) throws Exception {
}
}.execute(terminal, pluginZip, isBatch, env.v2());
}
Aggregations