Fix plugin installation logging

This commit is contained in:
Jason Tedor 2016-03-16 23:37:38 -04:00
parent ba6820caeb
commit dacb96ba61
2 changed files with 24 additions and 12 deletions

View File

@ -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));
}

View File

@ -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
}