diff --git a/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java b/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java index 3498f0b1ea725..1275cf83a5e97 100644 --- a/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java +++ b/server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java @@ -80,21 +80,29 @@ public void checkPermission(Permission perm) { final Elasticsearch elasticsearch = new Elasticsearch(); int status = main(args, elasticsearch, Terminal.DEFAULT); if (status != ExitCodes.OK) { - final String basePath = System.getProperty("es.logs.base_path"); - // It's possible to fail before logging has been configured, in which case there's no point - // suggesting that the user look in the log file. - if (basePath != null) { - Terminal.DEFAULT.errorPrintln( - "ERROR: Elasticsearch did not exit normally - check the logs at " - + basePath - + System.getProperty("file.separator") - + System.getProperty("es.logs.cluster_name") + ".log" - ); - } + printLogsSuggestion(); exit(status); } } + /** + * Prints a message directing the user to look at the logs. A message is only printed if + * logging has been configured. + */ + static void printLogsSuggestion() { + final String basePath = System.getProperty("es.logs.base_path"); + // It's possible to fail before logging has been configured, in which case there's no point + // suggesting that the user look in the log file. + if (basePath != null) { + Terminal.DEFAULT.errorPrintln( + "ERROR: Elasticsearch did not exit normally - check the logs at " + + basePath + + System.getProperty("file.separator") + + System.getProperty("es.logs.cluster_name") + ".log" + ); + } + } + private static void overrideDnsCachePolicyProperties() { for (final String property : new String[] {"networkaddress.cache.ttl", "networkaddress.cache.negative.ttl" }) { final String overrideProperty = "es." + property; diff --git a/server/src/main/java/org/elasticsearch/bootstrap/ElasticsearchUncaughtExceptionHandler.java b/server/src/main/java/org/elasticsearch/bootstrap/ElasticsearchUncaughtExceptionHandler.java index 601b9888c794a..a56e074a47c09 100644 --- a/server/src/main/java/org/elasticsearch/bootstrap/ElasticsearchUncaughtExceptionHandler.java +++ b/server/src/main/java/org/elasticsearch/bootstrap/ElasticsearchUncaughtExceptionHandler.java @@ -58,6 +58,8 @@ void onFatalUncaught(final String threadName, final Throwable t) { t.printStackTrace(Terminal.DEFAULT.getErrorWriter()); // Without a final flush, the stacktrace may not be shown before ES exits Terminal.DEFAULT.flush(); + + Elasticsearch.printLogsSuggestion(); } void onNonFatalUncaught(final String threadName, final Throwable t) {