解决打印org.apache.http.wire,org.apache.http.headers日志的问题

最近在调试接口的过程中,发现使用httpClient的时候,控制台输出了很多org.apache.http.wire,org.apache.http.headers相关的日志,不便于我观察自己调试业务过程中输出的日志,内容如下:

10:02:34.413 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> POST /apiservice HTTP/1.1
10:02:34.413 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Mozilla/5.0?(Windows?NT?6.1;?Win64;?x64;?rv:50.0)?Gecko/20100101?Firefox/50.0
10:02:34.413 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Length: 1251
10:02:34.413 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Type: application/x-www-form-urlencoded; charset=UTF-8
10:02:34.413 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: apitest.globebill.com
10:02:34.413 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive
10:02:34.413 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
10:02:34.413 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "POST /apiservice HTTP/1.1[\r][\n]"
10:02:34.413 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Mozilla/5.0[0xa0](Windows[0xa0]NT[0xa0]6.1;[0xa0]Win64;[0xa0]x64;[0xa0]rv:50.0)[0xa0]Gecko/20100101[0xa0]Firefox/50.0[\r][\n]"
10:02:34.413 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Length: 1251[\r][\n]"
10:02:34.413 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Type: application/x-www-form-urlencoded; charset=UTF-8[\r][\n]"
10:02:34.413 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: apitest.globebill.com[\r][\n]"
10:02:34.413 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
10:02:34.413 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
10:02:34.413 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]"
10:02:34.413 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "head=%7B%22apiCode%22%3A%22MCHT_00044%22%2C%22brhNo%22%3A%22NjCMtKQUX3A34%2FvPqxuP2A%3D%3D%22%2C%22regId%22%3A%222B9ED373E6A84CAC8814D81109F96417%22%2C%22scKey%22%3A%22mRGYbQIh%2Fooez%2FLIMP7Sup%2FgATz4qXVsEWQlZtXtrDss8ztQp8oSOzuZJ7fPXcsMU300uK0ciY%2FpD83hKxc%2BtJTsG16SfQnVJjTq7SS%2BDCeiqtgXP%2FWlmrmRHN%2FYAnq3ObBSXdGafQyDuz1RaDFSn6NlWtJ9MJIr%2FufSpXr2io4%3D%22%2C%22scOffSet%22%3A%22QI8gRSl4scTUhJZUPRy2UYt2HXtlpZP7A6m2dNPvML%2FEduCzjpab8iKDbM195MfZf%2FRE4LDjAoO0VSCu1hkuD9nS8p4XrOaw4lMGt5pofGRsu%2F47MF7vZcXIn5ktSGL9Tak1ycAxUzuwFiiFURpmwDb%2F1hrkqh%2FeE5nGZjrlExo%3D%22%2C%22txnDate%22%3A%2220230829%22%2C%22txnNo%22%3A%22c35b6b46-7c2d-44d0-bfbc-adef79893c1f%22%2C%22txnTime%22%3A%2220230829100234%22%7D&sign=T9G3s%2FOZXwOL6M3jdT3Y6zeyCsT2Ir470wjWTmJG5rcFnBgsNws9Qdz8iF7uvjeF11Zh8Z2qj2KyqoPtxUxz9CU84L4lYSe0ERlUtULsPdNk2TxRn58rM6B%2BN8bVhQCEdVo4Zgbn%2B0YoJ76gwMK%2Fr12nhZW7m4bwr85q2hV3lSus%2FA6nByiqmm4hylZBjCbTMyvxqXWbBoPO0ggLUqpiYNiWaJS1PryEu1w1RZEte35CYf%2BUTUoW9zyCg6G3BQe3BdxhnkFFbrLcmZ%2FYmCjX4QpH0nzjdk78uF5ZIAmW1pDOy0LfgTaqlqeb2u41BAQTTMDx46J6p28SIJru6cRHmQ%3D%3D&body=mmm0dThRBNm4IhrDp9k9IuFxo2Y6PHTcSL55C2xJ7WhpnlQI2p8h8w4l9%2BXuWBfEUUq%2BUPm%2F6x7nvZZmVxG5etcAx6clTJuiAn93a%2BMDTuLJAwFAlAUvHR2nRw%2BZXjjAUeTSfvdNqDM7KvX%2BA0f%2BQA%3D%3D"
10:02:35.312 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 200 [\r][\n]"
10:02:35.312 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Tue, 29 Aug 2023 02:02:39 GMT[\r][\n]"
10:02:35.312 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: text/plain;charset=UTF-8[\r][\n]"
10:02:35.312 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Length: 1170[\r][\n]"
10:02:35.312 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Connection: keep-alive[\r][\n]"
10:02:35.312 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Server: nginx[\r][\n]"
10:02:35.312 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Set-Cookie: JSESSIONID=F1893041057900DD536D81AC7BC3A88D; Path=/; HttpOnly[\r][\n]"
10:02:35.312 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "From: apitest.globebill.com[\r][\n]"
10:02:35.312 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]"

于是想办法把该部分日志过滤掉。具体的解决办法如下:

第一步:在module的main目录下创建resources目录(如果该目录已存在,则跳过该步);

第二步:在resources目录下创建logback.xml文件,文件内容如下:


    
    
    
    

    
        
            ${CONSOLE_LOG_PATTERN}
        
    
    //注意这个level级别,如果设置为ERROR,那么DEBUG,INFO
    
        
    

经过上面两步配置之后,再次运行程序,发现org.apache.http.wire和org.apache.http.headers相关的输出日志没有了,说明配置生效了。

你可能感兴趣的:(JAVA,apache,http,网络协议)