NIFI-7264 Make jsonPath Expression Logging More Reasonable

add special handling of PathNotFoundExceptions to log to debug
fix spelling error
wrap debug log in guard per review

This closes #4148

Signed-off-by: Mike Thomsen <mthomsen@apache.org>
This commit is contained in:
Otto Fowler 2020-03-17 11:27:21 -04:00 committed by Mike Thomsen
parent 943de310ad
commit 23fa2d3138
No known key found for this signature in database
GPG Key ID: 88511C3D4CAD246F
1 changed files with 10 additions and 0 deletions

View File

@ -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;
@ -46,7 +47,16 @@ public class JsonPathEvaluator extends JsonPathBaseEvaluator {
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;
}