在使用httpcomponents依赖时,调用请求生成了很多debug日志。
<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.3</version> </dependency>
很多情况下我们并不需要这么多内容,可能有时我们只需要输出Head,等等。
查询了下文章,有在资源目录中创建log4j.properties文件配置如下内容的。
log4j.rootLogger=INFO log4j.logger.org.apache.http.client=OFF log4j.logger.org.apache.http=OFF log4j.logger.org.apache.http.wire=OFF log4j.logger.httpclient.wire.header=OFF log4j.logger.httpclient.wire.content=OFF log4j.logger.org.apache.commons.httpclient=OFF
有直接设置系统环境的
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "info"); System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header", "info"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "info");
参考文章:http://hc.apache.org/httpcomponents-client-ga/logging.html
然而依然没有解决,最后参考这篇文章:https://codeday.me/bug/20170621/28219.html
创建文件 logback.xml ,问题得以平复。
<configuration> <logger name="org.apache" level="WARN" /> <logger name="httpclient" level="WARN" /> </configuration>
未经允许请勿转载:程序喵 » Java 禁用HttpClient日志记录