From d167b5eafb7b4c2c329bc1d5163676b63bd2385b Mon Sep 17 00:00:00 2001 From: zzz Date: Wed, 28 Feb 2018 20:04:40 +0000 Subject: [PATCH] LogManager: Don't register runtime shutdown hook in router context. This was causing shutdown() to be called twice, resulting in lost log messages when stopped from i2prouter. --- core/java/src/net/i2p/util/LogManager.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/java/src/net/i2p/util/LogManager.java b/core/java/src/net/i2p/util/LogManager.java index b668580df..50852992e 100644 --- a/core/java/src/net/i2p/util/LogManager.java +++ b/core/java/src/net/i2p/util/LogManager.java @@ -150,14 +150,18 @@ public class LogManager implements Flushable { // so it doesn't create a log directory and log files unless there is output. // In the router context, we have to rotate to a new log file at startup or the logs.jsp // page will display the old log. - if (context.isRouterContext()) + if (context.isRouterContext()) { startLogWriter(); - try { - Runtime.getRuntime().addShutdownHook(new ShutdownHook()); - } catch (IllegalStateException ise) { - // shutdown in progress, fsck it + } else { + // Only in App Context. + // In Router Context, the router has its own shutdown hook, + // and will call our shutdown() from Router.finalShutdown() + try { + Runtime.getRuntime().addShutdownHook(new ShutdownHook()); + } catch (IllegalStateException ise) { + // shutdown in progress + } } - //System.out.println("Created logManager " + this + " with context: " + context); } /** @since 0.8.2 */