Show stacktrace of startup exception

Whether or not the stacktrace is displayed is controlled by bootstrap
log level setting, so that bootstrap: DEBUG displays the stack trace on
output, like it does on log

Closes #5102
This commit is contained in:
Timo Rantalaiho 2014-02-12 21:53:23 +02:00 committed by Luca Cavanna
parent 4d6eb369a3
commit 3ae02b0b60
2 changed files with 13 additions and 0 deletions

View File

@ -23,6 +23,9 @@ import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.rest.RestStatus;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
*
*/
@ -110,4 +113,11 @@ public final class ExceptionsHelper {
return t.getClass().getSimpleName() + "[" + t.getMessage() + "]";
}
}
public static String stackTrace(Throwable e) {
StringWriter stackTraceStringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stackTraceStringWriter);
e.printStackTrace(printWriter);
return stackTraceStringWriter.toString();
}
}

View File

@ -274,6 +274,9 @@ public class Bootstrap {
} else {
errorMessage.append("- ").append(ExceptionsHelper.detailedMessage(e, true, 0));
}
if (Loggers.getLogger(Bootstrap.class).isDebugEnabled()) {
errorMessage.append("\n").append(ExceptionsHelper.stackTrace(e));
}
return errorMessage.toString();
}
}