angel_30
angel_30

Reputation: 1

JsonPath ignore the Debug logs on output

I'm using JsonPath for my JSON parsing work in Java. Is there any ways to remove the debug logs upon running the code?

So basically, I am simply trying to run my parsing code in Maven:

String pageName = JsonPath.read(json, "$['pageInfo']['pageName']");
        System.out.println(pageName);

But when running the jar artifact file, it show the following as the first line:

0 [main] DEBUG com.jayway.jsonpath.internal.path.CompiledPath - Evaluating path: $['pageInfo']['pageName']

How to ignore this line? This appears upon running each JsonPath.read() call.

UPDATES:

Initially I was getting some red-colored logs from log4j so added these dependencies. The red logs disappeared, but the above log (now black) appeared!

<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.5</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.5</version>
</dependency>

I also add the logBack dependency. But still the code snippet can not be recognized:

enter image description here

Upvotes: 4

Views: 3125

Answers (2)

SamHoque
SamHoque

Reputation: 3154

This question was actually asked on 2017 on their official github page.

Looks like you need to use a logback as the log implementation

here is the code provided by andreasaronsson from the github issue

LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory();
ch.qos.logback.classic.Logger log = logContext.getLogger("com.jayway.jsonpath.internal.path.CompiledPath");
log.setLevel(Level.INFO);

You need this in your dependencies

<dependencies>
   <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>2.11.1</version>
   </dependency>
   <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>2.11.1</version>
   </dependency>
   <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.2.3</version>
   </dependency>
</dependencies>

For more closure about the issue you can find it here

Upvotes: 4

madhead
madhead

Reputation: 33461

What logging framework are you using? Just set the level of com.jayway.jsonpath logger to INFO or higher. Below are examples of doing that with XML config for Logback and Log4j 2.

Logback:

<configuration>
  …
  <logger name="com.jayway.jsonpath" level="INFO"/>
  <root level="DEBUG">          
    <appender-ref ref="STDOUT" />
  </root>  
</configuration>

Log4j 2:

<Configuration status="WARN">
  …
  <Loggers>
    <Logger name="com.jayway.jsonpath" level="info">
      <AppenderRef ref="STDOUT"/>
    </Logger>
    <Root level="debug">
      <AppenderRef ref="STDOUT"/>
    </Root>
  </Loggers>
</Configuration>

Upvotes: 1

Related Questions