关闭apache httpclient4.5 DEBUG日志

今天有个小任务,需要调用接口同步数据,然后就写了一个JAVA类,打算直接本地执行main()去同步数据。

代码中使用了apache的httpclient来访问接口,发现输出日志太多了,

httpclient maven依赖如下:


     org.apache.httpcomponents
     httpclient
     4.5.2

日志输出示例如下:

11:37:01.845 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
11:37:01.845 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_121)[\r][\n]"
11:37:01.845 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]"
11:37:01.902 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 200 [\r][\n]"
11:37:01.903 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Tue, 09 Jul 2019 03:37:03 GMT[\r][\n]"
11:37:01.903 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: application/json;charset=UTF-8[\r][\n]"
11:37:01.903 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Transfer-Encoding: chunked[\r][\n]"
11:37:01.903 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Connection: keep-alive[\r][\n]"
11:37:01.903 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Application-Context: "
11:37:01.903 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Set-Cookie: JSESSIONID=29D13760D2D3E2493442448AA192DBDF;path=/;HttpOnly[\r][\n]"
11:37:01.903 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Expires: 0[\r][\n]"
11:37:01.903 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Content-Type-Options: nosniff[\r][\n]"
11:37:01.903 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-XSS-Protection: 1; mode=block[\r][\n]"
11:37:01.903 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Frame-Options: DENY[\r][\n]"

密密麻麻一堆的DEBUG日志,乌压压的,都是没什么用的信息。

请求单个接口还好,如果请求接口过多就会很快的覆盖掉关键的日志。

Apache官网文档也没有找到对应的说明,可能是我找的方法不对?附上官网地址:http://hc.apache.org/httpcomponents-client-4.5.x/logging.html

然后百度也没有找到很好的解决办法,大家都是千篇一律的粘贴复制,很是头疼。

自己捣鼓好半天。

最后的解决办法还是老套路:项目中增加logback.xml文件,文件路径看各自的项目,我的是springboot,就放在了resources目录下。然后logback.xml文件中配置如下:


    
    
    

    


    
        
            ${CONSOLE_LOG_PATTERN}
        
    

    
        
    

org.apache.http.wire:配置wire输入的日志级别的

org.apache.http.headers:配置headers输入的日志级别的

org.apache:配置org.apache路径下的相关的日志的输出的

改其他的日志的输出也是同理

其实这个配置不用多说,很简单很基础的logback的配置,只不过一时没想起来。这就很尴尬…

日志以记之。


原文链接:李锋镝的博客 >> https://www.lifengdi.com/archives/article/465

你可能感兴趣的:(java,apache,配置)