Skip to content

Commit

Permalink
Improve logging performance (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst committed Feb 3, 2023
1 parent 435c921 commit 5b15c46
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void addToEvaluatedProperties(String propertyPath) {
}

public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String at) {
if (logger.isDebugEnabled()) debug(logger, node, rootNode, at);
debug(logger, node, rootNode, at);

Set<ValidationMessage> errors = new LinkedHashSet<ValidationMessage>();
if (!node.isObject()) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/networknt/schema/BaseJsonValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ protected ValidationMessage buildValidationMessage(String at, String... argument
}

protected void debug(Logger logger, JsonNode node, JsonNode rootNode, String at) {
if (logger.isDebugEnabled()) {
logger.debug("validate( " + node + ", " + rootNode + ", " + at + ")");
}
logger.debug("validate( {}, {}, {})", node, rootNode, at);
}

protected ValidatorTypeCode getValidatorType() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/networknt/schema/DateTimeValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private boolean tryParse(Runnable parser) {
parser.run();
return true;
} catch (Exception ex) {
logger.error("Invalid " + formatName + ": " + ex.getMessage());
logger.error("Invalid {}: {}", formatName, ex.getMessage());
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/networknt/schema/FormatValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
}
} catch (PatternSyntaxException pse) {
// String is considered valid if pattern is invalid
logger.error("Failed to apply pattern on " + at + ": Invalid RE syntax [" + format.getName() + "]", pse);
logger.error("Failed to apply pattern on {}: Invalid RE syntax [{}]", at, format.getName(), pse);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/networknt/schema/JsonMetaSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public JsonValidator newValidator(ValidationContext validationContext, String sc
Keyword kw = keywords.get(keyword);
if (kw == null) {
if (UNKNOWN_KEYWORDS.put(keyword, keyword) == null) {
logger.warn("Unknown keyword " + keyword + " - you should define your own Meta Schema. If the keyword is irrelevant for validation, just use a NonValidationKeyword");
logger.warn("Unknown keyword {} - you should define your own Meta Schema. If the keyword is irrelevant for validation, just use a NonValidationKeyword", keyword);
}
return null;
}
Expand All @@ -289,13 +289,13 @@ public JsonValidator newValidator(ValidationContext validationContext, String sc
logger.error("Error:", e);
throw (JsonSchemaException) e.getTargetException();
} else {
logger.warn("Could not load validator " + keyword);
logger.warn("Could not load validator {}", keyword);
throw new JsonSchemaException(e.getTargetException());
}
} catch (JsonSchemaException e) {
throw e;
} catch (Exception e) {
logger.warn("Could not load validator " + keyword);
logger.warn("Could not load validator {}", keyword);
throw new JsonSchemaException(e);
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/networknt/schema/JsonSchemaFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,7 @@ private boolean idMatchesSourceUri(final JsonMetaSchema metaSchema, final JsonNo
return false;
}
boolean result = id.equals(schemaUri.toString());
if (logger.isDebugEnabled()) {
logger.debug("Matching " + id + " to " + schemaUri.toString() + ": " + result);
}
logger.debug("Matching {} to {}: {}", id, schemaUri, result);
return result;
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/networknt/schema/PatternValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public PatternValidatorJava(String schemaPath, JsonNode schemaNode, JsonSchema p
try {
compiledPattern = Pattern.compile(pattern);
} catch (PatternSyntaxException pse) {
logger.error("Failed to compile pattern : Invalid syntax [" + pattern + "]", pse);
logger.error("Failed to compile pattern : Invalid syntax [{}]", pattern, pse);
throw pse;
}
}
Expand All @@ -100,7 +100,7 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
return Collections.singleton(buildValidationMessage(at, pattern));
}
} catch (PatternSyntaxException pse) {
logger.error("Failed to apply pattern on " + at + ": Invalid syntax [" + pattern + "]", pse);
logger.error("Failed to apply pattern on {}: Invalid syntax [{}]", at, pattern, pse);
}

return Collections.emptySet();
Expand All @@ -121,7 +121,7 @@ public PatternValidatorEcma262(String schemaPath, JsonNode schemaNode, JsonSchem
try {
compileRegexPattern(pattern, validationContext.getConfig() != null && validationContext.getConfig().isEcma262Validator());
} catch (SyntaxException se) {
logger.error("Failed to compile pattern : Invalid syntax [" + pattern + "]", se);
logger.error("Failed to compile pattern : Invalid syntax [{}]", pattern, se);
throw se;
}
}
Expand Down Expand Up @@ -156,7 +156,7 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
return Collections.singleton(buildValidationMessage(at, pattern));
}
} catch (PatternSyntaxException pse) {
logger.error("Failed to apply pattern on " + at + ": Invalid syntax [" + pattern + "]", pse);
logger.error("Failed to apply pattern on {}: Invalid syntax [{}]", at, pattern, pse);
}

return Collections.emptySet();
Expand Down

0 comments on commit 5b15c46

Please sign in to comment.