This is an automated email from the ASF dual-hosted git repository. jsinovassinnaik pushed a commit to branch UNOMI-846 in repository https://gitbox.apache.org/repos/asf/unomi.git
commit 49aeb1db33daab699de44a6fd3fc1d989ec78597 Author: jsinovassin <jsinovassinn...@jahia.com> AuthorDate: Thu Aug 22 15:09:42 2024 +0200 UNOMI-846: improve log for event validation --- .../org/apache/unomi/schema/impl/SchemaServiceImpl.java | 16 +++++++++------- rest/src/main/java/org/apache/unomi/utils/HttpUtils.java | 2 -- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/extensions/json-schema/services/src/main/java/org/apache/unomi/schema/impl/SchemaServiceImpl.java b/extensions/json-schema/services/src/main/java/org/apache/unomi/schema/impl/SchemaServiceImpl.java index e30231c92..1e7fc9b94 100644 --- a/extensions/json-schema/services/src/main/java/org/apache/unomi/schema/impl/SchemaServiceImpl.java +++ b/extensions/json-schema/services/src/main/java/org/apache/unomi/schema/impl/SchemaServiceImpl.java @@ -88,6 +88,7 @@ public class SchemaServiceImpl implements SchemaService { JsonSchema jsonSchema = getJsonSchema(schemaId); return validate(jsonNode, jsonSchema).size() == 0; } catch (ValidationException e) { + logger.warn("An event was not valid - switch to DEBUG log level for more information."); if (logger.isDebugEnabled()) { logger.debug(e.getMessage(), e); } @@ -105,9 +106,7 @@ public class SchemaServiceImpl implements SchemaService { try { return validateEvent(event).size() == 0; } catch (ValidationException e) { - if (logger.isDebugEnabled()) { - logger.debug(e.getMessage(), e); - } + logger.warn(e.getMessage(), e); } return false; } @@ -139,7 +138,10 @@ public class SchemaServiceImpl implements SchemaService { } } } catch (ValidationException e) { - logger.debug("Validation error : {}", e.getMessage()); + logger.warn("An event was not valid - switch to DEBUG log level for more information."); + if (logger.isDebugEnabled()) { + logger.debug(e.getMessage(), e); + } Set<ValidationError> errors = buildCustomErrorMessage(e.getMessage()); String eventTypeOrErrorKey = eventType != null ? eventType : GENERIC_ERROR_KEY; if (errorsPerEventType.containsKey(eventTypeOrErrorKey)) { @@ -230,10 +232,10 @@ public class SchemaServiceImpl implements SchemaService { try { Set<ValidationMessage> validationMessages = jsonSchema.validate(jsonNode); - if (logger.isDebugEnabled() && validationMessages.size() > 0) { - logger.debug("Schema validation found {} errors while validating against schema: {}", validationMessages.size(), jsonSchema.getCurrentUri()); + if (validationMessages.size() > 0) { + logger.warn("Schema validation found {} errors while validating against schema: {}", validationMessages.size(), jsonSchema.getCurrentUri()); for (ValidationMessage validationMessage : validationMessages) { - logger.debug("Validation error: {}", validationMessage); + logger.warn("Validation error: {}", validationMessage); } } diff --git a/rest/src/main/java/org/apache/unomi/utils/HttpUtils.java b/rest/src/main/java/org/apache/unomi/utils/HttpUtils.java index 87572eb22..e1126e3a1 100644 --- a/rest/src/main/java/org/apache/unomi/utils/HttpUtils.java +++ b/rest/src/main/java/org/apache/unomi/utils/HttpUtils.java @@ -123,8 +123,6 @@ public class HttpUtils { for (JsonNode event : eventsNode) { if (schemaService.isEventValid(event.toString())) { filteredEvents.add(jsonParser.getCodec().treeToValue(event, Event.class)); - } else { - logger.error("An event was rejected - switch to DEBUG log level for more information OR test the payload of your event against the \"validateEvent\" endpoint."); } } return filteredEvents;