3

我正在使用JsonPathJava 中的 JSON 解析工作。有没有办法debug在运行代码时删除日志?

所以基本上,我只是想在 Maven 中运行我的解析代码:

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

但是在运行jar工件文件时,它会在第一行显示以下内容:

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

如何忽略这条线?这会在每次JsonPath.read()调用时出现。

更新

log4j最初,我从添加了这些依赖项中获取了一些红色日志。红色的原木消失了,但上面的原木(现在是黑色的)出现了!

<!-- 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>

我还添加了logBack依赖项。但仍然无法识别代码片段:

在此处输入图像描述

4

2 回答 2

3

这个问题实际上是在 2017 年在他们的官方 github 页面上提出的。

看起来您需要使用 logback 作为日志实现

这是 github issue 中 andreasaronsson 提供的代码

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

您在依赖项中需要它

<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>

有关该问题的更多关闭信息,您可以在此处找到它

于 2018-12-10T22:51:43.570 回答
0

您使用的是什么日志记录框架?只需将com.jayway.jsonpath记录器的级别设置为 INFO 或更高。下面是使用 XML 配置为LogbackLog4j 2执行此操作的示例。

回溯

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

日志4j 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>
于 2018-12-10T22:53:59.827 回答