diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/CheckCLDR.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/CheckCLDR.java index 9b9eabcf4fb..a5a7e85ce90 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/CheckCLDR.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/CheckCLDR.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; +import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.unicode.cldr.test.CheckCLDR.CheckStatus.Subtype; @@ -63,6 +64,14 @@ */ public abstract class CheckCLDR implements CheckAccessor { + /** protected so subclasses can use it */ + protected static Logger logger = Logger.getLogger(CheckCLDR.class.getSimpleName()); + + /** set the internal logger level. For ConsoleCheck. */ + public static void setLoggerLevel(java.util.logging.Level newLevel) { + logger.setLevel(newLevel); + } + /** serialize CheckCLDR as just its class name */ public String toString() { return getClass().getSimpleName(); @@ -964,13 +973,15 @@ public String getMessage() { } } catch (Exception e) { message = messageFormat; - System.err.println( + final String failMsg = "MessageFormat Failure: " + subtype + "; " + messageFormat + "; " - + (parameters == null ? null : Arrays.asList(parameters))); + + (parameters == null ? null : Arrays.asList(parameters)); + logger.log(java.util.logging.Level.SEVERE, e, () -> failMsg); + System.err.println(failMsg); // throw new IllegalArgumentException(subtype + "; " + messageFormat + "; " // + (parameters == null ? null : Arrays.asList(parameters)), e); } @@ -1406,6 +1417,19 @@ protected CheckCLDR handleGetExamples( } private void addError(List result, CheckCLDR item, Exception e) { + // send to java.util.logging, useful for servers + logger.log( + java.util.logging.Level.SEVERE, + e, + () -> { + String locale = "(unknown)"; + if (item.cldrFileToCheck != null) { + locale = item.cldrFileToCheck.getLocaleID(); + } + return String.format( + "Internal error: %s in %s", item.getClass().getName(), locale); + }); + // also add as a check result.add( new CheckStatus() .setCause(this) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ConsoleCheckCLDR.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ConsoleCheckCLDR.java index 69a6d424c1d..f8924e8447f 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ConsoleCheckCLDR.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ConsoleCheckCLDR.java @@ -344,6 +344,8 @@ static Level calculateCoverageLevel(final String coverageLevelInput, boolean for * @throws Throwable */ public static void main(String[] args) throws Throwable { + // turn off logging to not mess up html and other output. + CheckCLDR.setLoggerLevel(java.util.logging.Level.OFF); MyOptions.parse(args, true); ElapsedTimer totalTimer = new ElapsedTimer(); UOption.parseArgs(args, options);