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
*/
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;
}
