我在集成测试套件中使用commons-httpclient 3.1。HttpClient的默认日志记录非常嘈杂,我似乎无法将其关闭。我已经尝试按照此处的说明进行操作,但是它们都没有任何区别。
通常,我只需要关闭org.apache.http.wire logger。问题的部分原因是我不知道HttpClient尝试使用哪种类型的记录器,并且大多数问题是我以前从未使用过此库。我尝试创建一个log4j.properties文件并将其放入我的test / resources文件夹中,在jre / lib中修改主logging.properties文件,并按照日志记录页面上的指定将各种日志记录选项发送到Maven ,但没有一个有所作为。
任何帮助表示赞赏...这让我发疯。
更新:一项更正:似乎有问题的输出实际上是jwebunit对HttpClient的使用而不是我自己的。无论哪种方式,都是不可取的。
更新:感谢到目前为止的尝试。我已经尝试了下面建议的所有内容,但仍然没有运气。我的src / test / resources文件夹中有一个commons-logging.properties文件,内容如下
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]"
导线中所有内容的输出使该库对我不可用...直到我弄清楚如何将其关闭。为了读取此日志配置,我需要做些特殊的事情吗?
public class Main { static { System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog"); } // Rest of class as before }
-Dlog4j.debug
到VM选项中,以确保加载了正确的配置文件