Skip to content

Commit

Permalink
CLDR-17304 check: cause internalError to go to system logger
Browse files Browse the repository at this point in the history
- but add a facility so consolecheck does not see system logs
  • Loading branch information
srl295 committed Jan 10, 2024
1 parent 3074dbd commit 0c4341a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 26 additions & 2 deletions tools/cldr-code/src/main/java/org/unicode/cldr/test/CheckCLDR.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1406,6 +1417,19 @@ protected CheckCLDR handleGetExamples(
}

private void addError(List<CheckStatus> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0c4341a

Please sign in to comment.