From d87b6c4416a7b3e7f9843b02fda472c07900b87a Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Mon, 13 May 2019 11:02:45 +1000 Subject: [PATCH] Capture all logs and errors in the Pantheon log output (#1437) * Add slf4j to log4j bindings as a runtime dependency so any libraries that log to slf4j have their logs output to Pantheon's logs properly. * Set a default exception handler to ensure uncaught exceptions wind up in the Pantheon logs. Signed-off-by: Adrian Sutton --- pantheon/build.gradle | 1 + .../src/main/java/tech/pegasys/pantheon/Pantheon.java | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pantheon/build.gradle b/pantheon/build.gradle index 3c350b9dec..e42d4acd12 100644 --- a/pantheon/build.gradle +++ b/pantheon/build.gradle @@ -54,6 +54,7 @@ dependencies { implementation 'org.springframework.security:spring-security-crypto' runtime 'org.apache.logging.log4j:log4j-core' + runtime 'org.apache.logging.log4j:log4j-slf4j-impl' testImplementation project(':testutil') testImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts') diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java b/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java index 24b07ce2b2..81af487926 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/Pantheon.java @@ -21,6 +21,7 @@ import tech.pegasys.pantheon.ethereum.eth.sync.SynchronizerConfiguration; import tech.pegasys.pantheon.services.kvstore.RocksDbConfiguration; import tech.pegasys.pantheon.util.BlockImporter; +import org.apache.logging.log4j.Logger; import picocli.CommandLine.RunLast; public final class Pantheon { @@ -28,10 +29,13 @@ public final class Pantheon { private static final int ERROR_EXIT_CODE = 1; public static void main(final String... args) { - + final Logger logger = getLogger(); + Thread.setDefaultUncaughtExceptionHandler( + (thread, error) -> + logger.error("Uncaught exception in thread \"" + thread.getName() + "\"", error)); final PantheonCommand pantheonCommand = new PantheonCommand( - getLogger(), + logger, new BlockImporter(), new RunnerBuilder(), new PantheonController.Builder(),