我在一个集成测试套件中使用 commons-httpclient
3.1。HttpClient
的默认日志记录非常嘈杂,我似乎无法关闭它。我试着按照说明 给你操作,但是没有一个有效。
通常我只需要关闭 org.apache.http.wire 日志记录器。问题的一部分在于我不知道 HttpClient
试图使用哪种类型的日志记录器。我从没用过这个图书馆。我尝试创建一个 log4j.properties 文件并将其放到我的 test/resources 文件夹中,修改 jre/lib
中的主 logging.properties 文件,并按照 日志页面中的指定将各种日志选项发送给 Maven,但它们都没有任何作用。
更新: 一个更正: 看起来有问题的输出实际上是源于 jwebunit 对 HttpClient
的使用,而不是我自己的。不管怎样,这都是不可取的。
更新: 感谢迄今为止的尝试。我试了下面建议的所有方法,但仍然没有效果。我有一个文件 commons-logging.properties
在我的 src/test/resources
文件夹与以下内容
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.Log4jFactory
log4j.configuration=log4j.properties
以及同一文件夹中的 log4j.properties 文件,其内容如下
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
然而,当我运行我的测试时,我仍然会得到这样的输出:
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]"
这个输出的一切,通过线路是使这个库不可用的我... 这是直到我可以找出如何关闭它。要读入这个日志配置,我需要做什么特别的事情吗?