From e92b746252bedc344d08ecf9a10cca7a539fb266 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 27 Nov 2018 16:21:06 +0000 Subject: [PATCH] JAL-3163 only log missing message keys once each --- src/jalview/util/MessageManager.java | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/jalview/util/MessageManager.java b/src/jalview/util/MessageManager.java index 3dace12..2852364 100644 --- a/src/jalview/util/MessageManager.java +++ b/src/jalview/util/MessageManager.java @@ -21,11 +21,11 @@ package jalview.util; import java.text.MessageFormat; +import java.util.HashSet; import java.util.Locale; import java.util.ResourceBundle; import java.util.ResourceBundle.Control; -//import java.util.logging.Level; -//import java.util.logging.Logger; +import java.util.Set; import org.apache.log4j.Logger; @@ -48,6 +48,8 @@ public class MessageManager private static Locale loc; + private static Set reportedMissing = new HashSet<>(); + static { try @@ -86,7 +88,8 @@ public class MessageManager value = rb.getString(key); } catch (Exception e) { - log.warn("I18N missing: " + loc + "\t" + key); + String msg = "I18N missing: " + loc + "\t" + key; + logWarning(key, msg); } return value; } @@ -125,9 +128,25 @@ public class MessageManager name = rb.getString(smkey); } catch (Exception x) { - log.info("I18N missing key with root " + keyroot + ": " + loc + "\t" - + smkey); // was FINEST + String msg = "I18N missing key with root " + keyroot + ": " + loc + "\t" + + smkey; + logWarning(smkey, msg); } return name; } + + /** + * Logs missing keys (each key once only per run) + * + * @param key + * @param msg + */ + private static void logWarning(String key, String msg) + { + if (!reportedMissing.contains(key)) + { + reportedMissing.add(key); + log.info(msg); + } + } } -- 1.7.10.2