Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 669
angel_30 Avatar asked Oct 16 '25 13:10

angel_30


2 Answers

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

like image 128
SamHoque Avatar answered Oct 18 '25 08:10

SamHoque


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>
like image 31
madhead - StandWithUkraine Avatar answered Oct 18 '25 07:10

madhead - StandWithUkraine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!