Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-17304 capture internalError check stack traces into the system log #3447

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of disabling the log, how about capturing stderr and stdout separately as in java ... check ... 2> output.log 1> output.html?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@btangmu the errors are already handled as part of the checks in this case, though. This doesn't disable stderr.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't suppress any errors, it only suppresses printing out the logging in the ConsoleCheckCLDR tool environment.

MyOptions.parse(args, true);
ElapsedTimer totalTimer = new ElapsedTimer();
UOption.parseArgs(args, options);
Expand Down
Loading