Skip to content

Commit 5b15c46

Browse files
authored
Improve logging performance (#649)
1 parent 435c921 commit 5b15c46

File tree

7 files changed

+12
-16
lines changed

7 files changed

+12
-16
lines changed

src/main/java/com/networknt/schema/AdditionalPropertiesValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private void addToEvaluatedProperties(String propertyPath) {
7777
}
7878

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

8282
Set<ValidationMessage> errors = new LinkedHashSet<ValidationMessage>();
8383
if (!node.isObject()) {

src/main/java/com/networknt/schema/BaseJsonValidator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ protected ValidationMessage buildValidationMessage(String at, String... argument
151151
}
152152

153153
protected void debug(Logger logger, JsonNode node, JsonNode rootNode, String at) {
154-
if (logger.isDebugEnabled()) {
155-
logger.debug("validate( " + node + ", " + rootNode + ", " + at + ")");
156-
}
154+
logger.debug("validate( {}, {}, {})", node, rootNode, at);
157155
}
158156

159157
protected ValidatorTypeCode getValidatorType() {

src/main/java/com/networknt/schema/DateTimeValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private boolean tryParse(Runnable parser) {
7979
parser.run();
8080
return true;
8181
} catch (Exception ex) {
82-
logger.error("Invalid " + formatName + ": " + ex.getMessage());
82+
logger.error("Invalid {}: {}", formatName, ex.getMessage());
8383
return false;
8484
}
8585
}

src/main/java/com/networknt/schema/FormatValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
6363
}
6464
} catch (PatternSyntaxException pse) {
6565
// String is considered valid if pattern is invalid
66-
logger.error("Failed to apply pattern on " + at + ": Invalid RE syntax [" + format.getName() + "]", pse);
66+
logger.error("Failed to apply pattern on {}: Invalid RE syntax [{}]", at, format.getName(), pse);
6767
}
6868
}
6969

src/main/java/com/networknt/schema/JsonMetaSchema.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public JsonValidator newValidator(ValidationContext validationContext, String sc
278278
Keyword kw = keywords.get(keyword);
279279
if (kw == null) {
280280
if (UNKNOWN_KEYWORDS.put(keyword, keyword) == null) {
281-
logger.warn("Unknown keyword " + keyword + " - you should define your own Meta Schema. If the keyword is irrelevant for validation, just use a NonValidationKeyword");
281+
logger.warn("Unknown keyword {} - you should define your own Meta Schema. If the keyword is irrelevant for validation, just use a NonValidationKeyword", keyword);
282282
}
283283
return null;
284284
}
@@ -289,13 +289,13 @@ public JsonValidator newValidator(ValidationContext validationContext, String sc
289289
logger.error("Error:", e);
290290
throw (JsonSchemaException) e.getTargetException();
291291
} else {
292-
logger.warn("Could not load validator " + keyword);
292+
logger.warn("Could not load validator {}", keyword);
293293
throw new JsonSchemaException(e.getTargetException());
294294
}
295295
} catch (JsonSchemaException e) {
296296
throw e;
297297
} catch (Exception e) {
298-
logger.warn("Could not load validator " + keyword);
298+
logger.warn("Could not load validator {}", keyword);
299299
throw new JsonSchemaException(e);
300300
}
301301
}

src/main/java/com/networknt/schema/JsonSchemaFactory.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,7 @@ private boolean idMatchesSourceUri(final JsonMetaSchema metaSchema, final JsonNo
424424
return false;
425425
}
426426
boolean result = id.equals(schemaUri.toString());
427-
if (logger.isDebugEnabled()) {
428-
logger.debug("Matching " + id + " to " + schemaUri.toString() + ": " + result);
429-
}
427+
logger.debug("Matching {} to {}: {}", id, schemaUri, result);
430428
return result;
431429
}
432430

src/main/java/com/networknt/schema/PatternValidator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public PatternValidatorJava(String schemaPath, JsonNode schemaNode, JsonSchema p
7575
try {
7676
compiledPattern = Pattern.compile(pattern);
7777
} catch (PatternSyntaxException pse) {
78-
logger.error("Failed to compile pattern : Invalid syntax [" + pattern + "]", pse);
78+
logger.error("Failed to compile pattern : Invalid syntax [{}]", pattern, pse);
7979
throw pse;
8080
}
8181
}
@@ -100,7 +100,7 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
100100
return Collections.singleton(buildValidationMessage(at, pattern));
101101
}
102102
} catch (PatternSyntaxException pse) {
103-
logger.error("Failed to apply pattern on " + at + ": Invalid syntax [" + pattern + "]", pse);
103+
logger.error("Failed to apply pattern on {}: Invalid syntax [{}]", at, pattern, pse);
104104
}
105105

106106
return Collections.emptySet();
@@ -121,7 +121,7 @@ public PatternValidatorEcma262(String schemaPath, JsonNode schemaNode, JsonSchem
121121
try {
122122
compileRegexPattern(pattern, validationContext.getConfig() != null && validationContext.getConfig().isEcma262Validator());
123123
} catch (SyntaxException se) {
124-
logger.error("Failed to compile pattern : Invalid syntax [" + pattern + "]", se);
124+
logger.error("Failed to compile pattern : Invalid syntax [{}]", pattern, se);
125125
throw se;
126126
}
127127
}
@@ -156,7 +156,7 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
156156
return Collections.singleton(buildValidationMessage(at, pattern));
157157
}
158158
} catch (PatternSyntaxException pse) {
159-
logger.error("Failed to apply pattern on " + at + ": Invalid syntax [" + pattern + "]", pse);
159+
logger.error("Failed to apply pattern on {}: Invalid syntax [{}]", at, pattern, pse);
160160
}
161161

162162
return Collections.emptySet();

0 commit comments

Comments
 (0)