From dacb96ba61d6f6a419bfaf60c70db8bf43d5c8da Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 16 Mar 2016 23:37:38 -0400 Subject: [PATCH] Fix plugin installation logging --- .../org/elasticsearch/plugins/PluginCli.java | 18 +++++++++++++++--- .../scripts/module_and_plugin_test_cases.bash | 18 +++++++++--------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginCli.java b/core/src/main/java/org/elasticsearch/plugins/PluginCli.java index 323b872044e..be06ea7db1c 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginCli.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginCli.java @@ -19,10 +19,9 @@ package org.elasticsearch.plugins; -import org.apache.log4j.BasicConfigurator; -import org.apache.log4j.varia.NullAppender; import org.elasticsearch.cli.MultiCommand; import org.elasticsearch.cli.Terminal; +import org.elasticsearch.common.logging.LogConfigurator; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.node.internal.InternalSettingsPreparer; @@ -40,7 +39,20 @@ public class PluginCli extends MultiCommand { } public static void main(String[] args) throws Exception { - BasicConfigurator.configure(new NullAppender()); + // initialize default for es.logger.level because we will not read the logging.yml + String loggerLevel = System.getProperty("es.logger.level", "INFO"); + // Set the appender for all potential log files to terminal so that other components that use the logger print out the + // same terminal. + // The reason for this is that the plugin cli cannot be configured with a file appender because when the plugin command is + // executed there is no way of knowing where the logfiles should be placed. For example, if elasticsearch + // is run as service then the logs should be at /var/log/elasticsearch but when started from the tar they should be at es.home/logs. + // Therefore we print to Terminal. + Environment loggingEnvironment = InternalSettingsPreparer.prepareEnvironment(Settings.builder() + .put("appender.terminal.type", "terminal") + .put("rootLogger", "${es.logger.level}, terminal") + .put("es.logger.level", loggerLevel) + .build(), Terminal.DEFAULT); + LogConfigurator.configure(loggingEnvironment.settings(), false); Environment env = InternalSettingsPreparer.prepareEnvironment(Settings.EMPTY, Terminal.DEFAULT); exit(new PluginCli(env).main(args, Terminal.DEFAULT)); } diff --git a/qa/vagrant/src/test/resources/packaging/scripts/module_and_plugin_test_cases.bash b/qa/vagrant/src/test/resources/packaging/scripts/module_and_plugin_test_cases.bash index b654fa990ed..e92c4b62b76 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/module_and_plugin_test_cases.bash +++ b/qa/vagrant/src/test/resources/packaging/scripts/module_and_plugin_test_cases.bash @@ -423,14 +423,14 @@ fi local loglines=$(cat /tmp/plugin-cli-output | wc -l) if [ "$GROUP" == "TAR PLUGINS" ]; then # tar extraction does not create the plugins directory so the plugin tool will print an additional line that the directory will be created - [ "$loglines" -eq "7" ] || { - echo "Expected 7 lines but the output was:" + [ "$loglines" -eq "3" ] || { + echo "Expected 3 lines but the output was:" cat /tmp/plugin-cli-output false } else - [ "$loglines" -eq "6" ] || { - echo "Expected 6 lines but the output was:" + [ "$loglines" -eq "2" ] || { + echo "Expected 2 lines but the output was:" cat /tmp/plugin-cli-output false } @@ -438,17 +438,17 @@ fi remove_jvm_example local relativePath=${1:-$(readlink -m jvm-example-*.zip)} - sudo -E -u $ESPLUGIN_COMMAND_USER "$ESHOME/bin/elasticsearch-plugin" install "file://$relativePath" -Ees.logger.level=DEBUG > /tmp/plugin-cli-output + sudo -E -u $ESPLUGIN_COMMAND_USER "$ESHOME/bin/elasticsearch-plugin" install "file://$relativePath" -Des.logger.level=DEBUG > /tmp/plugin-cli-output local loglines=$(cat /tmp/plugin-cli-output | wc -l) if [ "$GROUP" == "TAR PLUGINS" ]; then - [ "$loglines" -gt "7" ] || { - echo "Expected more than 7 lines but the output was:" + [ "$loglines" -gt "3" ] || { + echo "Expected more than 3 lines but the output was:" cat /tmp/plugin-cli-output false } else - [ "$loglines" -gt "6" ] || { - echo "Expected more than 6 lines but the output was:" + [ "$loglines" -gt "2" ] || { + echo "Expected more than 2 lines but the output was:" cat /tmp/plugin-cli-output false }