Jochen Berger
12 years ago
6 changed files with 25 additions and 104 deletions
@ -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); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
@ -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"); |
||||
|
||||
} |
||||
} |
@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<configuration> |
||||
<contextName>myAppName</contextName> |
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> |
||||
<encoder> |
||||
<pattern>%-5level [%t] %logger{36} - %msg%n</pattern> |
||||
</encoder> |
||||
</appender> |
||||
|
||||
<logger name="com.jayway.jsonpath" level="TRACE"/> |
||||
|
||||
<root level="debug"> |
||||
<appender-ref ref="STDOUT" /> |
||||
</root> |
||||
</configuration> |
Loading…
Reference in new issue