diff --git a/src/main/java/org/elasticsearch/ExceptionsHelper.java b/src/main/java/org/elasticsearch/ExceptionsHelper.java index 2f075a46a41..da17c95e643 100644 --- a/src/main/java/org/elasticsearch/ExceptionsHelper.java +++ b/src/main/java/org/elasticsearch/ExceptionsHelper.java @@ -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(); + } } diff --git a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index 28aa9383a07..90a4a75049c 100644 --- a/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -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(); } }