Browse Source

Reduce the amount of logging by the library

pull/127/head
Archimedes Trajano 10 years ago committed by Archimedes Trajano
parent
commit
0c61f5b309
  1. 25
      json-path/src/main/java/com/jayway/jsonpath/Criteria.java
  2. 4
      json-path/src/main/java/com/jayway/jsonpath/Filter.java
  3. 11
      json-path/src/main/java/com/jayway/jsonpath/internal/CompiledPath.java
  4. 24
      json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java
  5. 15
      json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java
  6. 10
      json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayPathToken.java
  7. 5
      json-path/src/main/java/com/jayway/jsonpath/internal/token/PredicateContextImpl.java

25
json-path/src/main/java/com/jayway/jsonpath/Criteria.java

@ -17,8 +17,6 @@ package com.jayway.jsonpath;
import com.jayway.jsonpath.internal.Path;
import com.jayway.jsonpath.internal.PathCompiler;
import com.jayway.jsonpath.internal.token.PredicateContextImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.math.BigDecimal;
import java.util.Arrays;
@ -37,8 +35,6 @@ import static com.jayway.jsonpath.internal.Utils.notNull;
@SuppressWarnings("unchecked")
public class Criteria implements Predicate {
private static final Logger logger = LoggerFactory.getLogger(Criteria.class);
private static final String[] OPERATORS = {
CriteriaType.EQ.toString(),
CriteriaType.GTE.toString(),
@ -60,7 +56,6 @@ public class Criteria implements Predicate {
@Override
boolean eval(Object expected, Object model, PredicateContext ctx) {
boolean res = (0 == safeCompare(expected, model));
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), expected, res);
return res;
}
@ -73,7 +68,6 @@ public class Criteria implements Predicate {
@Override
boolean eval(Object expected, Object model, PredicateContext ctx) {
boolean res = (0 != safeCompare(expected, model));
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), expected, res);
return res;
}
@ -89,7 +83,6 @@ public class Criteria implements Predicate {
return false;
}
boolean res = (0 > safeCompare(expected, model));
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), expected, res);
return res;
}
@ -105,7 +98,6 @@ public class Criteria implements Predicate {
return false;
}
boolean res = (0 >= safeCompare(expected, model));
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), expected, res);
return res;
}
@ -121,7 +113,6 @@ public class Criteria implements Predicate {
return false;
}
boolean res = (0 < safeCompare(expected, model));
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), expected, res);
return res;
}
@ -137,7 +128,6 @@ public class Criteria implements Predicate {
return false;
}
boolean res = (0 <= safeCompare(expected, model));
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), expected, res);
return res;
}
@ -157,7 +147,6 @@ public class Criteria implements Predicate {
break;
}
}
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), join(", ", exps), res);
return res;
}
},
@ -166,7 +155,6 @@ public class Criteria implements Predicate {
boolean eval(Object expected, Object model, PredicateContext ctx) {
Collection nexps = (Collection) expected;
boolean res = !nexps.contains(model);
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), join(", ", nexps), res);
return res;
}
},
@ -188,7 +176,6 @@ public class Criteria implements Predicate {
res = ((String) model).contains((String)expected);
}
}
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", model, name(), expected, res);
return res;
}
},
@ -211,11 +198,8 @@ public class Criteria implements Predicate {
break;
}
}
if (logger.isDebugEnabled())
logger.debug("[{}] {} [{}] => {}", join(", ", ctx.configuration().jsonProvider().toIterable(model)), name(), join(", ", exps), res);
} else {
res = false;
if (logger.isDebugEnabled()) logger.debug("[{}] {} [{}] => {}", "<NOT AN ARRAY>", name(), join(", ", exps), res);
}
return res;
}
@ -228,15 +212,11 @@ public class Criteria implements Predicate {
if (ctx.configuration().jsonProvider().isArray(model)) {
int length = ctx.configuration().jsonProvider().length(model);
res = (length == size);
if (logger.isDebugEnabled()) logger.debug("Array with size {} {} {} => {}", length, name(), size, res);
} else if (model instanceof String) {
int length = ((String) model).length();
res = length == size;
if (logger.isDebugEnabled()) logger.debug("String with length {} {} {} => {}", length, name(), size, res);
} else {
res = false;
if (logger.isDebugEnabled())
logger.debug("{} {} {} => {}", model == null ? "null" : model.getClass().getName(), name(), size, res);
}
return res;
}
@ -275,8 +255,6 @@ public class Criteria implements Predicate {
if (target != null) {
res = pattern.matcher(target.toString()).matches();
}
if (logger.isDebugEnabled())
logger.debug("[{}] {} [{}] => {}", model == null ? "null" : model.toString(), name(), expected == null ? "null" : expected.toString(), res);
return res;
}
@ -301,11 +279,9 @@ public class Criteria implements Predicate {
if (ctx.configuration().jsonProvider().isArray(model)) {
int len = ctx.configuration().jsonProvider().length(model);
res = (0 != len);
if (logger.isDebugEnabled()) logger.debug("array length = {} {} => {}", len, name(), res);
} else if (model instanceof String) {
int len = ((String) model).length();
res = (0 != len);
if (logger.isDebugEnabled()) logger.debug("string length = {} {} => {}", len, name(), res);
}
}
return res;
@ -842,7 +818,6 @@ public class Criteria implements Predicate {
Boolean a = (Boolean) right;
return e.compareTo(a);
} else {
logger.debug("Can not compare a {} with a {}", left.getClass().getName(), right.getClass().getName());
throw new ValueCompareException();
}
}

4
json-path/src/main/java/com/jayway/jsonpath/Filter.java

@ -15,8 +15,6 @@
package com.jayway.jsonpath;
import com.jayway.jsonpath.internal.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collection;
@ -30,7 +28,6 @@ import static java.util.Arrays.asList;
*/
public abstract class Filter implements Predicate {
private static final Logger logger = LoggerFactory.getLogger(Filter.class);
private static final Pattern OPERATOR_SPLIT = Pattern.compile("((?<=&&|\\|\\|)|(?=&&|\\|\\|))");
private static final String AND = "&&";
private static final String OR = "||";
@ -192,7 +189,6 @@ public abstract class Filter implements Predicate {
throw new InvalidPathException("Invalid operators " + filter);
}
if(logger.isDebugEnabled()) logger.debug("Parsed filter: " + root.toString());
return root;
}

11
json-path/src/main/java/com/jayway/jsonpath/internal/CompiledPath.java

@ -17,20 +17,13 @@ package com.jayway.jsonpath.internal;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.internal.token.EvaluationContextImpl;
import com.jayway.jsonpath.internal.token.PathToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CompiledPath implements Path {
private static final Logger logger = LoggerFactory.getLogger(CompiledPath.class);
private final PathToken root;
private final boolean isRootPath;
public CompiledPath(PathToken root, boolean isRootPath) {
this.root = root;
this.isRootPath = isRootPath;
@ -43,10 +36,6 @@ public class CompiledPath implements Path {
@Override
public EvaluationContext evaluate(Object document, Object rootDocument, Configuration configuration, boolean forUpdate) {
if (logger.isDebugEnabled()) {
logger.debug("Evaluating path: {}", toString());
}
EvaluationContextImpl ctx = new EvaluationContextImpl(this, rootDocument, configuration, forUpdate);
try {
PathRef op = ctx.forUpdate() ? PathRef.createRoot(rootDocument) : PathRef.NO_OP;

24
json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java

@ -23,8 +23,6 @@ import com.jayway.jsonpath.ParseContext;
import com.jayway.jsonpath.Predicate;
import com.jayway.jsonpath.ReadContext;
import com.jayway.jsonpath.TypeRef;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
@ -38,8 +36,6 @@ import static com.jayway.jsonpath.internal.Utils.notNull;
public class JsonReader implements ParseContext, DocumentContext {
private static final Logger logger = LoggerFactory.getLogger(JsonReader.class);
private final Configuration configuration;
private Object json;
private Object patch;
@ -186,11 +182,6 @@ public class JsonReader implements ParseContext, DocumentContext {
@Override
public DocumentContext set(JsonPath path, Object newValue){
List<String> modified = path.set(json, newValue, configuration.addOptions(Option.AS_PATH_LIST));
if(logger.isDebugEnabled()){
for (String p : modified) {
logger.debug("Set path {} new value {}", p, newValue);
}
}
return this;
}
@ -202,11 +193,6 @@ public class JsonReader implements ParseContext, DocumentContext {
@Override
public DocumentContext delete(JsonPath path) {
List<String> modified = path.delete(json, configuration.addOptions(Option.AS_PATH_LIST));
if(logger.isDebugEnabled()){
for (String p : modified) {
logger.debug("Delete path {}");
}
}
return this;
}
@ -218,11 +204,6 @@ public class JsonReader implements ParseContext, DocumentContext {
@Override
public DocumentContext add(JsonPath path, Object value){
List<String> modified = path.add(json, value, configuration.addOptions(Option.AS_PATH_LIST));
if(logger.isDebugEnabled()){
for (String p : modified) {
logger.debug("Add path {} new value {}", p, value);
}
}
return this;
}
@ -234,11 +215,6 @@ public class JsonReader implements ParseContext, DocumentContext {
@Override
public DocumentContext put(JsonPath path, String key, Object value){
List<String> modified = path.put(json, key, value, configuration.addOptions(Option.AS_PATH_LIST));
if(logger.isDebugEnabled()){
for (String p : modified) {
logger.debug("Put path {} key {} value {}", p, key, value);
}
}
return this;
}

15
json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java

@ -24,8 +24,6 @@ import com.jayway.jsonpath.internal.token.PropertyPathToken;
import com.jayway.jsonpath.internal.token.RootPathToken;
import com.jayway.jsonpath.internal.token.ScanPathToken;
import com.jayway.jsonpath.internal.token.WildcardPathToken;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.LinkedList;
@ -37,8 +35,6 @@ import static java.util.Arrays.asList;
public class PathCompiler {
private static final Logger logger = LoggerFactory.getLogger(PathCompiler.class);
private static final String PROPERTY_OPEN = "['";
private static final String PROPERTY_CLOSE = "']";
private static final char DOCUMENT = '$';
@ -81,7 +77,6 @@ public class PathCompiler {
String cacheKey = Utils.concat(trimmedPath, Boolean.toString(isRootPath), filterList.toString());
Path p = cache.get(cacheKey);
if (p != null) {
if (logger.isDebugEnabled()) logger.debug("Using cached path: {}", cacheKey);
return p;
}
@ -475,16 +470,6 @@ public class PathCompiler {
}
singleIndex = (numbers.size() == 1) && !sliceTo && !sliceFrom && !contextSize;
if (logger.isTraceEnabled()) {
logger.debug("numbers are : {}", numbers.toString());
logger.debug("sequence is singleNumber : {}", singleIndex);
logger.debug("sequence is numberSequence : {}", indexSequence);
logger.debug("sequence is sliceFrom : {}", sliceFrom);
logger.debug("sequence is sliceTo : {}", sliceTo);
logger.debug("sequence is sliceBetween : {}", sliceBetween);
logger.debug("sequence is contextFetch : {}", contextSize);
logger.debug("---------------------------------------------");
}
ArrayPathToken.Operation operation = null;
if (singleIndex) operation = ArrayPathToken.Operation.SINGLE_INDEX;

10
json-path/src/main/java/com/jayway/jsonpath/internal/token/ArrayPathToken.java

@ -18,8 +18,6 @@ import com.jayway.jsonpath.InvalidPathException;
import com.jayway.jsonpath.PathNotFoundException;
import com.jayway.jsonpath.internal.PathRef;
import com.jayway.jsonpath.internal.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
@ -30,8 +28,6 @@ import static java.lang.String.format;
*/
public class ArrayPathToken extends PathToken {
private static final Logger logger = LoggerFactory.getLogger(ArrayPathToken.class);
public static enum Operation {
CONTEXT_SIZE,
SLICE_TO,
@ -94,8 +90,6 @@ public class ArrayPathToken extends PathToken {
}
from = Math.max(0, from);
logger.debug("Slice from index on array with length: {}. From index: {} to: {}. Input: {}", length, from, length - 1, toString());
if (length == 0 || from >= length) {
return;
}
@ -114,8 +108,6 @@ public class ArrayPathToken extends PathToken {
}
to = Math.min(length, to);
logger.debug("Slice to index on array with length: {}. From index: 0 to: {}. Input: {}", length, to, toString());
if (length == 0) {
return;
}
@ -135,8 +127,6 @@ public class ArrayPathToken extends PathToken {
return;
}
logger.debug("Slice between indexes on array with length: {}. From index: {} to: {}. Input: {}", length, from, to, toString());
for (int i = from; i < to; i++) {
handleArrayIndex(i, currentPath, model, ctx);
}

5
json-path/src/main/java/com/jayway/jsonpath/internal/token/PredicateContextImpl.java

@ -18,15 +18,11 @@ import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.Predicate;
import com.jayway.jsonpath.internal.Path;
import com.jayway.jsonpath.spi.mapper.MappingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
public class PredicateContextImpl implements Predicate.PredicateContext {
private static final Logger logger = LoggerFactory.getLogger(PredicateContextImpl.class);
private final Object contextDocument;
private final Object rootDocument;
private final Configuration configuration;
@ -43,7 +39,6 @@ public class PredicateContextImpl implements Predicate.PredicateContext {
Object result;
if(path.isRootPath()){
if(documentPathCache.containsKey(path)){
logger.debug("Using cached result for root path: " + path.toString());
result = documentPathCache.get(path);
} else {
result = path.evaluate(rootDocument, rootDocument, configuration).getValue();

Loading…
Cancel
Save