禁用HttpClient日志记录 [英] Disable HttpClient logging

查看:141
本文介绍了禁用HttpClient日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在集成测试套件中使用commons-httpclient 3.1。 HttpClient的默认日志记录非常嘈杂,我似乎无法将其关闭。我已经尝试按照此处的说明进行操作,但它们都没有任何区别。

I am using commons-httpclient 3.1 in an integration test suite. The default logging for HttpClient is extremely noisy and I can't seem to turn it off. I've tried following the instructions here but none of them make any difference.

大多数情况下,我只需要关闭org.apache.http.wire记录器。问题的一部分是我不知道HttpClient尝试使用什么类型的记录器,大多数问题是我之前从未使用过这个库。我尝试创建一个log4j.properties文件并将其放在我的test / resources文件夹中,修改jre / lib中的master logging.properties文件,并按照记录页面,但没有一个有任何区别。

Mostly I just need to make the org.apache.http.wire logger shut up. Part of the problem is that I don't know what type of logger HttpClient is trying to use and most of the problem is I've never used this library before. I tried creating a log4j.properties file and dropping it in my test/resources folder, modifying the master logging.properties file in jre/lib, and sending in the various logging options to Maven as specified on the logging page, and none of them make any difference.

任何感谢帮助...这让我疯狂。

Any help is appreciated...this is driving me nuts.

更新:更正:看来有问题的输出实际上是通过jwebunit发起的使用HttpClient,不是我自己的。无论哪种方式,这都是不可取的。

UPDATE: A correction: it appears the output in question is actually originating through jwebunit's usage of HttpClient, not my own. Either way, it's not desirable.

更新:感谢目前为止的尝试。我已经尝试了下面提出的所有建议,但仍然没有运气。我的src / test / resources文件夹中有一个文件commons-logging.properties,内容如下:

UPDATE: Thanks for the attempts so far. I've tried everything suggested below but still no luck. I have a file commons-logging.properties in my src/test/resources folder with the following contents

org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.Log4jFactory
log4j.configuration=log4j.properties

和文件log4j.properties在同一文件夹中,包含以下内容

and a file log4j.properties in the same folder with the following contents

log4j.rootLogger=ERROR, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n

#This is the line that should make httpclient shut up
log4j.logger.org.apache.http=ERROR

然而,当我运行我的测试时,我仍然得到一堆这样的输出:

However, when I run my tests I still get a bunch of output like this:

21:57:41.413 [main] DEBUG org.apache.http.wire - << "                                   [\r][\n]"
21:57:41.413 [main] DEBUG org.apache.http.wire - << "[\r][\n]"
21:57:41.413 [main] DEBUG org.apache.http.wire - << "                                   [\r][\n]"
21:57:41.413 [main] DEBUG org.apache.http.wire - << "                               </ul>[\n]"
21:57:41.413 [main] DEBUG org.apache.http.wire - << "    [\n]"
21:57:41.424 [main] DEBUG org.apache.http.wire - << "[\n]"
21:57:41.425 [main] DEBUG org.apache.http.wire - << "[\r][\n]"
21:57:41.425 [main] DEBUG org.apache.http.wire - << "[\r][\n]"
21:57:41.425 [main] DEBUG org.apache.http.wire - << "                   </div>[\r][\n]"
21:57:41.425 [main] DEBUG org.apache.http.wire - << "                </li>[\r][\n]"
21:57:41.425 [main] DEBUG org.apache.http.wire - << "            [\r][\n]"
21:57:41.425 [main] DEBUG org.apache.http.wire - << "            [\r][\n]"
21:57:41.433 [main] DEBUG org.apache.http.wire - << "        </ul>[\n]"
21:57:41.433 [main] DEBUG org.apache.http.wire - << "</div>[\n]"
21:57:41.433 [main] DEBUG org.apache.http.wire - << "[\n]"
21:57:41.433 [main] DEBUG org.apache.http.wire - << "</div>[\n]"
21:57:41.433 [main] DEBUG org.apache.http.wire - << "[\n]"
21:57:41.433 [main] DEBUG org.apache.http.wire - << "[\n]"
21:57:41.433 [main] DEBUG org.apache.http.wire - << "[\n]"
21:57:41.433 [main] DEBUG org.apache.http.wire - << "[\n]"
21:57:41.433 [main] DEBUG org.apache.http.wire - << "<div class="details">[\n]"
21:57:41.442 [main] DEBUG org.apache.http.wire - << "[\n]"
21:57:41.443 [main] DEBUG org.apache.http.wire - << "[\n]"
21:57:41.443 [main] DEBUG org.apache.http.wire - << "<div class="details-body details-precis  ">[\n]
"
21:57:41.443 [main] DEBUG org.apache.http.wire - << "<div class="details-state">[\n]"
21:57:41.443 [main] DEBUG org.apache.http.wire - << "[\n]"
21:57:41.443 [main] DEBUG org.apache.http.wire - << "</div>[\n]"
21:57:41.443 [main] DEBUG org.apache.http.wire - << "</div>[\n]"
21:57:41.443 [main] DEBUG org.apache.http.wire - << "[\n]"
21:57:41.455 [main] DEBUG org.apache.http.wire - << "[\n]"
21:57:41.455 [main] DEBUG org.apache.http.wire - << "</div>[\n]"
21:57:41.455 [main] DEBUG org.apache.http.wire - << "[\n]"
21:57:41.455 [main] DEBUG org.apache.http.wire - << "</div>[\n]"
21:57:41.455 [main] DEBUG org.apache.http.wire - << "</div>[\n]"
21:57:41.455 [main] DEBUG org.apache.http.wire - << "[\n]"
21:57:41.455 [main] DEBUG org.apache.http.wire - << "[\n]"
21:57:41.455 [main] DEBUG org.apache.http.wire - << "[\n]"
21:57:41.455 [main] DEBUG org.apache.http.wire - << "[\r][\n]"
Destroying 1 processes21:57:41.465 [main] DEBUG org.apache.http.wire - << "[\r][\n]"

此输出适用于电汇中的所有内容正在使这个库无法使用...直到我能弄清楚如何关闭它。我需要做些什么特别的事情才能读入这个日志配置?

This output for everything that comes across the wire is making this library unusable for me...that is until I can figure out how to turn it off. Is there anything special I need to do to get this log configuration read in?

推荐答案

更新 log4j。属性包括:

log4j.logger.httpclient.wire.header=WARN
log4j.logger.httpclient.wire.content=WARN






请注意,如果未安装Log4j库,HttpClient(以及JWebUnit)将使用logback。在这种情况下,创建或编辑 logback.xml 以包含:

<configuration>
    <logger name="org.apache" level="WARN" />
    <logger name="httpclient" level="WARN" /> 
</configuration>






将日志级别设置为 WARN log4j.properties org.apache.commons.httpclient c> 将无法正常工作


Setting the log level to WARN with Log4j using the package name org.apache.commons.httpclient in log4j.properties will not work as expected:

log4j.logger.org.apache.commons.httpclient=WARN

这是因为HttpClient(v3.1)的源使用以下日志名称:

This is because the source for HttpClient (v3.1) uses the following log names:

public static Wire HEADER_WIRE = new Wire(LogFactory.getLog("httpclient.wire.header"));
public static Wire CONTENT_WIRE = new Wire(LogFactory.getLog("httpclient.wire.content"));

这篇关于禁用HttpClient日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆