From: gmungoc Date: Tue, 27 Nov 2018 16:21:06 +0000 (+0000) Subject: JAL-3163 only log missing message keys once each X-Git-Tag: Release_2_11_4_0~45^2~18^2~363 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e92b746252bedc344d08ecf9a10cca7a539fb266;p=jalview.git JAL-3163 only log missing message keys once each --- 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); + } + } }