禁用apache.http.wire DEBUG日志记录

3
我是使用Travis CI与我的github仓库(Java项目)一起使用。我的一个测试使用SPARQL和Jena从Dbpedia获取数据。这导致我在日志中看到的记录太多,最终导致Travis失败。
例如,以下是一条日志:
14:52:58.756 [main] DEBUG org.apache.http.wire - http-outgoing-1 << "    {   
"pname": { "type": "literal", "xml:lang": "en", "value": "Yuen Poovarawan"
 }[0x9], "photo": { "type": "uri", "value": "http://commons.wikimedia.org 
 /wiki/Special:FilePath/Yuen_Poovarawan.jpg?width=300" }[0x9], "birth": { 
"type": "uri", "value": "http://dbpedia.org/resource/Thailand" }[0x9], 
"bDate": { "type": "typed-literal", "datatype": "http://www.w3.org
/2001/XMLSchema#date",   "value": "1950-11-05" }[0x9], "bExp": { "type": 
"uri", "value": "http://dbpedia.org/resource/Thailand" }},[\n]" 

所有这些日志都以[main] DEBUG org.apache.http.wire开头。我该如何禁用它们,以便Travis通过测试? 我发现了如何使用scala/logback.xml禁用它的方法,但是log.xml仅适用于控制台。我需要帮助正确使用它,请您帮忙/指导一下?

2
这不是Jena的问题。某种方式,至少org.apache.http.wire的调试级别日志已经被打开(它不是Jena的一部分)。理想情况下,设置您的日志记录,以便"org.apache.http"上不包括DEBUG。org.apache.http.wire似乎不是当前版本的Jena使用的http-components、http-client的一部分。 - AndyS
1个回答

4
创建一个包含以下内容的logback.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <logger name="org.apache" level="ERROR" />
    <logger name="httpclient" level="ERROR" />
</configuration>

将logback.xml放入你的java源代码目录中,这样它就会被包含在jar文件中。否则,从logback.xml创建一个jar文件,并将此jar文件放入你获取所有jar文件的lib中。

从logback.xml创建logback.jar的简单方法是使用ant。 创建以下代码的build.xml:

<?xml version='1.0'?>
<project name="test" default="compile" basedir=".">
<target name = "build-jar">
   <jar destfile = "op/logback.jar"
      basedir = "in">
      <manifest>
        <attribute name = "Main-Class" value = "com.tutorialspoint.util.FaxUtil"/>
      </manifest>
   </jar>
</target>
</project>

创建一个目录结构如下: |-- build.xml |-- in --> logback.xml |-- op --> logback.jar // 执行 ant 命令后会生成此文件
现在使用 ant build-jar 进行编译,你将获得 logback.jar。将这个 jar 文件与其他所有 jar 文件放在一起,它将删除 org.apache.http.wire 的 DEBUG 日志。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接