Skip to content

Commit

Permalink
Show stacktrace of startup exception
Browse files Browse the repository at this point in the history
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
  • Loading branch information
timorantalaiho authored and javanna committed Apr 4, 2014
1 parent e6b82b6 commit ed7995d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/elasticsearch/ExceptionsHelper.java
Expand Up @@ -23,6 +23,9 @@
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.rest.RestStatus;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
*
*/
Expand Down Expand Up @@ -110,4 +113,11 @@ public static String detailedMessage(Throwable t, boolean newLines, int initialC
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();
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/elasticsearch/bootstrap/Bootstrap.java
Expand Up @@ -274,6 +274,9 @@ private static String buildErrorMessage(String stage, Throwable e) {
} 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();
}
}

0 comments on commit ed7995d

Please sign in to comment.