From a59cad006667c17e314dc14dfb940e3d4b8ac8e1 Mon Sep 17 00:00:00 2001 From: zzz <zzz@i2pmail.org> Date: Sun, 5 Dec 2021 07:21:57 -0500 Subject: [PATCH] Router: Tweak shutdown messages Change one from CRIT to WARN Translate one of them Attempt to translate class name in notifications --- apps/routerconsole/java/bundle-messages.sh | 1 + core/java/src/net/i2p/util/LogWriter.java | 6 +++++- router/java/src/net/i2p/router/Router.java | 16 ++++++++++++++-- .../net/i2p/router/tasks/GracefulShutdown.java | 14 ++++++++------ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/apps/routerconsole/java/bundle-messages.sh b/apps/routerconsole/java/bundle-messages.sh index 6ff85e4689..19bcba45c5 100755 --- a/apps/routerconsole/java/bundle-messages.sh +++ b/apps/routerconsole/java/bundle-messages.sh @@ -39,6 +39,7 @@ fi # router/ now has its own bundle for some files ROUTERFILES="\ ../../../router/java/src/net/i2p/router/Blocklist.java \ + ../../../router/java/src/net/i2p/router/Router.java \ ../../../router/java/src/net/i2p/router/networkdb/reseed/Reseeder.java \ ../../../router/java/src/net/i2p/router/sybil/Analysis.java \ ../../../router/java/src/net/i2p/router/tasks/CoalesceStatsEvent.java \ diff --git a/core/java/src/net/i2p/util/LogWriter.java b/core/java/src/net/i2p/util/LogWriter.java index 9d7275e1e4..450c51a345 100644 --- a/core/java/src/net/i2p/util/LogWriter.java +++ b/core/java/src/net/i2p/util/LogWriter.java @@ -166,6 +166,7 @@ abstract class LogWriter implements Runnable { } private static final String BUNDLE_NAME = "net.i2p.util.messages"; + private static final String ROUTER_BUNDLE_NAME = "net.i2p.router.web.messages"; /** * gettext @@ -222,7 +223,10 @@ abstract class LogWriter implements Runnable { if (name == null) name = "I2P"; } - ns.notify(name, null, priority, name, msg, null); + // the class name usually won't be translated, + // but it will be for "Router" + String tname = Translate.getString(name, _manager.getContext(), ROUTER_BUNDLE_NAME); + ns.notify(name, null, priority, tname, msg, null); } } } diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java index 1576e44feb..83acdeb06d 100644 --- a/router/java/src/net/i2p/router/Router.java +++ b/router/java/src/net/i2p/router/Router.java @@ -108,6 +108,7 @@ public class Router implements RouterClock.ClockShiftListener { private UPnPScannerCallback _upnpScannerCallback; private long _downtime = -1; + private static final String BUNDLE_NAME = "net.i2p.router.web.messages"; public final static String PROP_CONFIG_FILE = "router.configLocation"; /** let clocks be off by 1 minute */ @@ -1443,7 +1444,10 @@ public class Router implements RouterClock.ClockShiftListener { // help us shut down esp. after OOM int priority = (exitCode == EXIT_OOM) ? Thread.MAX_PRIORITY - 1 : Thread.NORM_PRIORITY + 2; Thread.currentThread().setPriority(priority); - _log.log(Log.CRIT, "Starting final shutdown(" + exitCode + ')'); + if (exitCode == EXIT_HARD_RESTART || exitCode == EXIT_GRACEFUL_RESTART) + _log.log(Log.CRIT, _t("Restart imminent")); + else + _log.log(Log.CRIT, _t("Shutdown imminent")); // So we can get all the way to the end // No, you can't do Thread.currentThread.setDaemon(false) if (_killVMOnEnd) { @@ -1943,7 +1947,7 @@ public class Router implements RouterClock.ClockShiftListener { f.delete(); if (lastWritten > 0) _eventLog.addEvent(EventLog.CRASHED, - Translate.getString("{0} ago", DataHelper.formatDuration2(downtime), _context, "net.i2p.router.web.messages")); + Translate.getString("{0} ago", DataHelper.formatDuration2(downtime), _context, BUNDLE_NAME)); } else { return false; } @@ -2137,4 +2141,12 @@ public class Router implements RouterClock.ClockShiftListener { recv = (int)rs.getRate(5*60*1000).getAverageValue(); return Math.max(send, recv); } + + /** + * Translate with console bundle + * @since 0.9.53 + */ + private final String _t(String s) { + return Translate.getString(s, _context, BUNDLE_NAME); + } } diff --git a/router/java/src/net/i2p/router/tasks/GracefulShutdown.java b/router/java/src/net/i2p/router/tasks/GracefulShutdown.java index 5d86a291b0..ba2c4d49f1 100644 --- a/router/java/src/net/i2p/router/tasks/GracefulShutdown.java +++ b/router/java/src/net/i2p/router/tasks/GracefulShutdown.java @@ -26,12 +26,14 @@ public class GracefulShutdown implements Runnable { int gracefulExitCode = _context.router().scheduledGracefulExitCode(); if (gracefulExitCode == Router.EXIT_HARD || gracefulExitCode == Router.EXIT_HARD_RESTART || _context.tunnelManager().getParticipatingCount() <= 0) { - if (gracefulExitCode == Router.EXIT_HARD) - log.log(Log.CRIT, "Shutting down after a brief delay"); - else if (gracefulExitCode == Router.EXIT_HARD_RESTART) - log.log(Log.CRIT, "Restarting after a brief delay"); - else - log.log(Log.CRIT, "Graceful shutdown progress: No more tunnels, starting final shutdown"); + if (log.shouldWarn()) { + if (gracefulExitCode == Router.EXIT_HARD) + log.warn("Shutting down after a brief delay"); + else if (gracefulExitCode == Router.EXIT_HARD_RESTART) + log.warn("Restarting after a brief delay"); + else + log.warn("Graceful shutdown progress: No more tunnels, starting final shutdown"); + } // Allow time for a UI reponse try { synchronized (Thread.currentThread()) { -- GitLab