From 4e2337252877ff4ede2dfd06ff4a69cb8a3db794 Mon Sep 17 00:00:00 2001 From: Jochen Berger Date: Wed, 28 Aug 2013 12:34:49 +0200 Subject: [PATCH] use slf4j for logging --- json-path/pom.xml | 4 ++ .../java/com/jayway/jsonpath/JsonPath.java | 10 ++-- .../com/jayway/jsonpath/internal/Log.java | 50 ------------------- .../java/com/jayway/jsonpath/LogTest.java | 22 -------- json-path/src/test/resources/logback-test.xml | 15 ------ pom.xml | 28 ++++++----- 6 files changed, 25 insertions(+), 104 deletions(-) delete mode 100644 json-path/src/main/java/com/jayway/jsonpath/internal/Log.java delete mode 100644 json-path/src/test/java/com/jayway/jsonpath/LogTest.java delete mode 100644 json-path/src/test/resources/logback-test.xml diff --git a/json-path/pom.xml b/json-path/pom.xml index 84d775e1..43b124aa 100644 --- a/json-path/pom.xml +++ b/json-path/pom.xml @@ -34,6 +34,10 @@ org.apache.commons commons-lang3 + + org.slf4j + slf4j-api + org.codehaus.jackson jackson-mapper-asl diff --git a/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java b/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java index 1821525b..b67faf5d 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java +++ b/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java @@ -16,14 +16,16 @@ package com.jayway.jsonpath; import com.jayway.jsonpath.internal.IOUtils; -import com.jayway.jsonpath.internal.Log; import com.jayway.jsonpath.internal.PathToken; import com.jayway.jsonpath.internal.PathTokenizer; import com.jayway.jsonpath.internal.filter.PathTokenFilter; import com.jayway.jsonpath.spi.HttpProviderFactory; import com.jayway.jsonpath.spi.JsonProvider; import com.jayway.jsonpath.spi.JsonProviderFactory; + import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileInputStream; @@ -105,6 +107,8 @@ public class JsonPath { private PathTokenizer tokenizer; private LinkedList filters; + + private final Logger logger = LoggerFactory.getLogger(JsonPath.class); private JsonPath(String jsonPath, Filter[] filters) { @@ -122,9 +126,7 @@ public class JsonPath { this.tokenizer = new PathTokenizer(jsonPath); - if(Log.isDebugEnabled()){ - Log.debug("New JsonPath:\n{}", this.tokenizer.toString()); - } + logger.debug("New JsonPath:\n{}", this.tokenizer); this.filters = new LinkedList(); this.filters.addAll(asList(filters)); diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/Log.java b/json-path/src/main/java/com/jayway/jsonpath/internal/Log.java deleted file mode 100644 index 7c571d25..00000000 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/Log.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.jayway.jsonpath.internal; - -import org.apache.commons.lang3.StringUtils; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * User: kalle - * Date: 8/28/13 - * Time: 10:23 AM - */ -public final class Log { - - private Log() { - } - - private static boolean enabled = false; - - public static void enableDebug(){ - enabled = true; - } - - public static boolean isDebugEnabled(){ - return enabled; - } - - public static void debug(String msg, Object... args){ - if(enabled){ - - int argCount = StringUtils.countMatches(msg, "{}"); - - if(!(argCount == args.length)){ - throw new RuntimeException("Invalid debug statement."); - } - - StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); - - String cls = stackTraceElements[2].getClassName(); - - msg = msg.replaceFirst(Pattern.quote("{}"), "%s"); - - msg = String.format(msg, args); - - System.out.println("DEBUG [" + Thread.currentThread().getName() + "] " + cls + " " + msg); - } - - } - -} diff --git a/json-path/src/test/java/com/jayway/jsonpath/LogTest.java b/json-path/src/test/java/com/jayway/jsonpath/LogTest.java deleted file mode 100644 index cd3b9b9b..00000000 --- a/json-path/src/test/java/com/jayway/jsonpath/LogTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.jayway.jsonpath; - -import com.jayway.jsonpath.internal.Log; -import org.junit.Test; - -/** - * User: kalle - * Date: 8/28/13 - * Time: 10:40 AM - */ -public class LogTest { - - - @Test - public void logger_expands_templates() { - - Log.enableDebug(); - - Log.debug("foo \n{}", "bar"); - - } -} diff --git a/json-path/src/test/resources/logback-test.xml b/json-path/src/test/resources/logback-test.xml deleted file mode 100644 index 5c536ae4..00000000 --- a/json-path/src/test/resources/logback-test.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - myAppName - - - %-5level [%t] %logger{36} - %msg%n - - - - - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 20a3680a..821991cb 100644 --- a/pom.xml +++ b/pom.xml @@ -57,7 +57,6 @@ UTF-8 1.7.5 - 1.0.13 4.10 2.4 3.1 @@ -125,7 +124,16 @@ 1.6 - + + org.apache.maven.plugins + maven-surefire-plugin + 2.16 + + + debug + + + @@ -232,11 +240,11 @@ - ch.qos.logback - logback-classic - ${logback.version} + org.slf4j + slf4j-simple + ${slf4j.version} - + junit junit @@ -268,13 +276,7 @@ org.slf4j - slf4j-api - test - - - - ch.qos.logback - logback-classic + slf4j-simple test