Skip to content

Commit

Permalink
NIFI-7264 Make jsonPath Expression Logging More Reasonable
Browse files Browse the repository at this point in the history
add special handling of PathNotFoundExceptions to log to debug
fix spelling error
wrap debug log in guard per review

This closes apache#4148

Signed-off-by: Mike Thomsen <mthomsen@apache.org>
  • Loading branch information
ottobackwards authored and driesva committed Mar 19, 2021
1 parent 304af8a commit 4c7608a
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.nifi.attribute.expression.language.evaluation.functions;

import com.jayway.jsonpath.PathNotFoundException;
import org.apache.nifi.attribute.expression.language.EvaluationContext;
import org.apache.nifi.attribute.expression.language.evaluation.Evaluator;
import org.apache.nifi.attribute.expression.language.evaluation.QueryResult;
Expand Down Expand Up @@ -46,7 +47,16 @@ public QueryResult<String> evaluate(EvaluationContext context) {
Object result = null;
try {
result = documentContext.read(compiledJsonPath);
} catch (PathNotFoundException pnf) {
// it is valid for a path not to be found, keys may not be there
// do not spam the error log for this, instead we can log debug if enabled
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("PathNotFoundException for JsonPath " + compiledJsonPath.getPath(), pnf);
}
return EMPTY_RESULT;
} catch (Exception e) {
// a failure for something *other* than path not found however, should at least be
// logged.
LOGGER.error("Exception while reading JsonPath " + compiledJsonPath.getPath(), e);
return EMPTY_RESULT;
}
Expand Down

0 comments on commit 4c7608a

Please sign in to comment.