Apache HttpClient库的日志级别设置原理

简介: Apache HttpClient库的日志级别设置原理

在你的业务类的构造函数里调用下面这个enable方法,以启用日志:

private void enableHeaderWireAndContextLogging(){
    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.header", "debug");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");
    System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "debug");
  }

在SimpleLog的实现里,下列代码会从SystemProperty里读取用户用代码进行的设置:

image.pngdebug级别的日志输出很全:


2019/05/24 16:58:16:397 CST [DEBUG] RequestAddCookies - CookieSpec selected: default

2019/05/24 16:58:16:417 CST [DEBUG] RequestAuthCache - Auth cache not set in the context

2019/05/24 16:58:16:614 CST [DEBUG] PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://hybris.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]

2019/05/24 16:58:21:265 CST [DEBUG] PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {s}->https://hybris.com:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]

2019/05/24 16:58:21:271 CST [DEBUG] MainClientExec - Opening connection {s}->https://hybris.com:443

2019/05/24 16:58:21:271 CST [DEBUG] DefaultHttpClientConnectionOperator - Connecting to hybris.com/69.145.197.197:443

2019/05/24 16:58:21:271 CST [DEBUG] SSLConnectionSocketFactory - Connecting socket to hybris.com/69.145.197.197:443 with timeout 0

2019/05/24 16:58:21:521 CST [DEBUG] SSLConnectionSocketFactory - Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]

2019/05/24 16:58:21:521 CST [DEBUG] SSLConnectionSocketFactory - Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]

2019/05/24 16:58:21:521 CST [DEBUG] SSLConnectionSocketFactory - Starting handshake

2019/05/24 16:58:21:849 CST [DEBUG] SSLConnectionSocketFactory - Secure session established

2019/05/24 16:58:21:849 CST [DEBUG] SSLConnectionSocketFactory - negotiated protocol: TLSv1.2

2019/05/24 16:58:21:849 CST [DEBUG] SSLConnectionSocketFactory - negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256

2019/05/24 16:58:21:849 CST [DEBUG] SSLConnectionSocketFactory - peer principal: CN=gdm-acdo.apjdemo.hybris.com

2019/05/24 16:58:21:849 CST [DEBUG] SSLConnectionSocketFactory - peer alternative names: []

2019/05/24 16:58:21:849 CST [DEBUG] SSLConnectionSocketFactory - issuer principal: CN=Let’s Encrypt Authority X3, O=Let’s Encrypt, C=US

2019/05/24 16:58:21:849 CST [DEBUG] DefaultHttpClientConnectionOperator - Connection established 10.130.197.181:60875<->169.145.197.197:443

2019/05/24 16:58:21:849 CST [DEBUG] MainClientExec - Executing request GET /sap/opu/odata/sap/CUAN_CONTACT_SRV HTTP/1.1

2019/05/24 16:58:21:849 CST [DEBUG] MainClientExec - Proxy auth state: UNCHALLENGED

2019/05/24 16:58:21:849 CST [DEBUG] headers - http-outgoing-0 >> GET /sap/opu/odata/sap/CUAN_CONTACT_SRV HTTP/1.1

2019/05/24 16:58:21:849 CST [DEBUG] headers - http-outgoing-0 >> Authorization: basic bWt0X2R

2019/05/24 16:58:21:849 CST [DEBUG] headers - http-outgoing-0 >> Cache-Control: no-cache

2019/05/24 16:58:21:849 CST [DEBUG] headers - http-outgoing-0 >> content-type: application/json

2019/05/24 16:58:21:849 CST [DEBUG] headers - http-outgoing-0 >> Accept: application/json

2019/05/24 16:58:21:849 CST [DEBUG] headers - http-outgoing-0 >> x-csrf-token: fetch

2019/05/24 16:58:21:849 CST [DEBUG] headers - http-outgoing-0 >> Host: gdm-hybris.com

2019/05/24 16:58:21:849 CST [DEBUG] headers - http-outgoing-0 >> Connection: Keep-Alive

2019/05/24 16:58:21:849 CST [DEBUG] headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.1 (Java/1.8.0_60)

2019/05/24 16:58:21:849 CST [DEBUG] headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate

2019/05/24 16:58:21:849 CST [DEBUG] wire - http-outgoing-0 >> “GET /sap/opu/odata/sap/CUAN_CONTACT_SRV HTTP/1.1[\r][\n]”

2019/05/24 16:58:21:849 CST [DEBUG] wire - http-outgoing-0 >> “Authorization: basic bWt0X2[\r][\n]”

2019/05/24 16:58:21:849 CST [DEBUG] wire - http-outgoing-0 >> “Cache-Control: no-cache[\r][\n]”

2019/05/24 16:58:21:849 CST [DEBUG] wire - http-outgoing-0 >> “content-type: application/json[\r][\n]”

2019/05/24 16:58:21:849 CST [DEBUG] wire - http-outgoing-0 >> “Accept: application/json[\r][\n]”

2019/05/24 16:58:21:849 CST [DEBUG] wire - http-outgoing-0 >> “x-csrf-token: fetch[\r][\n]”

2019/05/24 16:58:21:849 CST [DEBUG] wire - http-outgoing-0 >> “Host: gdm-acdo.apjdemo.hybris.com[\r][\n]”

2019/05/24 16:58:21:849 CST [DEBUG] wire - http-outgoing-0 >> “Connection: Keep-Alive[\r][\n]”

2019/05/24 16:58:21:849 CST [DEBUG] wire - http-outgoing-0 >> “User-Agent: Apache-HttpClient/4.5.1 (Java/1.8.0_60)[\r][\n]”

2019/05/24 16:58:21:849 CST [DEBUG] wire - http-outgoing-0 >> “Accept-Encoding: gzip,deflate[\r][\n]”

2019/05/24 16:58:21:849 CST [DEBUG] wire - http-outgoing-0 >> “[\r][\n]”

2019/05/24 16:58:22:061 CST [DEBUG] wire - http-outgoing-0 << “HTTP/1.1 307 Temporary Redirect[\r][\n]”

2019/05/24 16:58:22:061 CST [DEBUG] wire - http-outgoing-0 << “Server: nginx/1.14.2[\r][\n]”

2019/05/24 16:58:22:061 CST [DEBUG] wire - http-outgoing-0 << “Date: Fri, 24 May 2019 08:58:22 GMT[\r][\n]”

2019/05/24 16:58:22:061 CST [DEBUG] wire - http-outgoing-0 << “Content-Length: 0[\r][\n]”

2019/05/24 16:58:22:061 CST [DEBUG] wire - http-outgoing-0 << “Connection: keep-alive[\r][\n]”

2019/05/24 16:58:22:061 CST [DEBUG] wire - http-outgoing-0 << “set-cookie: sap-usercontext=sap-client=100; path=/[\r][\n]”

2019/05/24 16:58:22:061 CST [DEBUG] wire - http-outgoing-0 << “set-cookie: SAP_SEhIHE%3d; path=/; secure; HttpOnly[\r][\n]”

2019/05/24 16:58:22:061 CST [DEBUG] wire - http-outgoing-0 << “x-csrf-token: kVwN39IxT6wSsOnjgeSGww==[\r][\n]”

2019/05/24 16:58:22:061 CST [DEBUG] wire - http-outgoing-0 << “location: https://hybris.com:443/sap/opu/odata/sap/CUAN_CONTACT_SRV/[\r][\n]

2019/05/24 16:58:22:061 CST [DEBUG] wire - http-outgoing-0 << “sap-processing-info: ODataBEP=,crp=,st=,MedCacheHub=,codeployed=X,softstate=[\r][\n]”

2019/05/24 16:58:22:061 CST [DEBUG] wire - http-outgoing-0 << “sap-server: true[\r][\n]”

2019/05/24 16:58:22:061 CST [DEBUG] wire - http-outgoing-0 << “sap-perf-fesrec: 42584.000000[\r][\n]”

2019/05/24 16:58:22:061 CST [DEBUG] wire - http-outgoing-0 << “[\r][\n]”

2019/05/24 16:58:22:061 CST [DEBUG] headers - http-outgoing-0 << HTTP/1.1 307 Temporary Redirect

2019/05/24 16:58:22:061 CST [DEBUG] headers - http-outgoing-0 << Server: nginx/1.14.2

2019/05/24 16:58:22:061 CST [DEBUG] headers - http-outgoing-0 << Date: Fri, 24 May 2019 08:58:22 GMT

2019/05/24 16:58:22:061 CST [DEBUG] headers - http-outgoing-0 << Content-Length: 0

2019/05/24 16:58:22:061 CST [DEBUG] headers - http-outgoing-0 << Connection: keep-alive

2019/05/24 16:58:22:061 CST [DEBUG] headers - http-outgoing-0 << set-cookie: sap-usercontext=sap-client=100; path=/

2019/05/24 16:58:22:061 CST [DEBUG] headers - http-outgoing-0 << set-cookie: SAP_SESSIONID_E4T_100=a-dtZMlUCPrNMQYUQYcL8RULy6l-AhHpqRECAAohIHE%3d; path=/; secure; HttpOnly

2019/05/24 16:58:22:061 CST [DEBUG] headers - http-outgoing-0 << x-csrf-token: kVwSGww==

2019/05/24 16:58:22:061 CST [DEBUG] headers - http-outgoing-0 << location: https://hybris.com:443/sap/opu/odata/sap/CUAN_CONTACT_SRV/

2019/05/24 16:58:22:061 CST [DEBUG] headers - http-outgoing-0 << sap-processing-info: ODataBEP=,crp=,st=,MedCacheHub=,codeployed=X,softstate=

2019/05/24 16:58:22:061 CST [DEBUG] headers - http-outgoing-0 << sap-server: true

2019/05/24 16:58:22:061 CST [DEBUG] headers - http-outgoing-0 << sap-perf-fesrec: 42584.000000

2019/05/24 16:58:22:061 CST [DEBUG] MainClientExec - Connection can be kept alive indefinitely

2019/05/24 16:58:22:061 CST [DEBUG] PoolingHttpClientConnectionManager - Connection [id: 0][route: {s}->https://hybris.com:443] can be kept alive indefinitely

2019/05/24 16:58:22:061 CST [DEBUG] PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {s}->https://hybris.com:443][total kept alive: 1; route allocated: 1 of 2; total allocated: 1 of 20]

2019/05/24 16:58:22:061 CST [DEBUG] ResponseProcessCookies - Cookie accepted [sap-usercontext=“sap-client=100”, version:0, domain:hybris.com, path:/, expiry:null]

2019/05/24 16:58:22:061 CST [DEBUG] ResponseProcessCookies - Cookie accepted [SAP_SESSIONID_E4T_100=“a-dtZMlUCPrNMQYUQYcL8RULy6l-AhHpqRECAAohIHE%3d”, version:0, domain:gdm-acdo.apjdemo.hybris.com, path:/, expiry:null]

2019/05/24 16:58:22:925 CST [DEBUG] DefaultRedirectStrategy - Redirect requested to location ‘https://hybris.com:443/sap/opu/odata/sap/CUAN_CONTACT_SRV/

2019/05/24 16:58:24:219 CST [DEBUG] RedirectExec - Redirecting to ‘https://hybris.com:443/sap/opu/odata/sap/CUAN_CONTACT_SRV/’ via {s}->https://gdm-acdo.apjdemo.hybris.com:443

2019/05/24 16:58:24:230 CST [DEBUG] RequestAddCookies - CookieSpec selected: default

2019/05/24 16:58:24:230 CST [DEBUG] RequestAddCookies - Cookie [version: 0][name: SAP_SESSIONID_E4T_100][value: a-dtZMlUCPrNMQYUQYcL8RULy6l-AhHpqRECAAohIHE%3d][domain: gdm-acdo.apjdemo.hybris.com][path: /][expiry: null] match [(secure)hybris.com:443/sap/opu/odata/sap/CUAN_CONTACT_SRV/]

2019/05/24 16:58:24:230 CST [DEBUG] RequestAddCookies - Cookie [version: 0][name: sap-usercontext][value: sap-client=100][domain: gdm-acdo.apjdemo.hybris.com][path: /][expiry: null] match [(secure)hybris.com:443/sap/opu/odata/sap/CUAN_CONTACT_SRV/]

2019/05/24 16:58:24:231 CST [DEBUG] RequestAuthCache - Auth cache not set in the context

2019/05/24 16:58:24:995 CST [DEBUG] PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://hybris.com:443][total kept alive: 1; route allocated: 1 of 2; total allocated: 1 of 20]

2019/05/24 16:58:24:997 CST [DEBUG] wire - http-outgoing-0 << “[read] I/O error: Read timed out”

2019/05/24 16:58:24:997 CST [DEBUG] PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {s}->https://hybris.com:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]

2019/05/24 16:58:24:998 CST [DEBUG] MainClientExec - Executing request GET /sap/opu/odata/sap/CUAN_CONTACT_SRV/ HTTP/1.1

2019/05/24 16:58:24:998 CST [DEBUG] MainClientExec - Proxy auth state: UNCHALLENGED

2019/05/24 16:58:24:998 CST [DEBUG] headers - http-outgoing-0 >> GET /sap/opu/odata/sap/CUAN_CONTACT_SRV/ HTTP/1.1

2019/05/24 16:58:24:998 CST [DEBUG] headers - http-outgoing-0 >> Authorization: basic bWt0X2Rl5

2019/05/24 16:58:24:998 CST [DEBUG] headers - http-outgoing-0 >> Cache-Control: no-cache

2019/05/24 16:58:24:998 CST [DEBUG] headers - http-outgoing-0 >> content-type: application/json

2019/05/24 16:58:24:998 CST [DEBUG] headers - http-outgoing-0 >> Accept: application/json

2019/05/24 16:58:24:998 CST [DEBUG] headers - http-outgoing-0 >> x-csrf-token: fetch

2019/05/24 16:58:24:998 CST [DEBUG] headers - http-outgoing-0 >> Host: gdm-acdo.apjdemo.hybris.com:443

2019/05/24 16:58:24:998 CST [DEBUG] headers - http-outgoing-0 >> Connection: Keep-Alive

2019/05/24 16:58:24:998 CST [DEBUG] headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.1 (Java/1.8.0_60)

2019/05/24 16:58:24:998 CST [DEBUG] headers - http-outgoing-0 >> Cookie: SAP_SESSIONID_E4T_100=a-dtZMlUYcL8RULy6l-AhHpqRECAAohIHE%3d; sap-usercontext=sap-client=100

2019/05/24 16:58:24:998 CST [DEBUG] headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate

2019/05/24 16:58:24:998 CST [DEBUG] wire - http-outgoing-0 >> “GET /sap/opu/odata/sap/CUAN_CONTACT_SRV/ HTTP/1.1[\r][\n]”

2019/05/24 16:58:24:999 CST [DEBUG] wire - http-outgoing-0 >> “Authorization: basic bWt0X2RldjpNWVdlbGNvbWU5[\r][\n]”

2019/05/24 16:58:24:999 CST [DEBUG] wire - http-outgoing-0 >> “Cache-Control: no-cache[\r][\n]”

2019/05/24 16:58:24:999 CST [DEBUG] wire - http-outgoing-0 >> “content-type: application/json[\r][\n]”

2019/05/24 16:58:24:999 CST [DEBUG] wire - http-outgoing-0 >> “Accept: application/json[\r][\n]”

2019/05/24 16:58:24:999 CST [DEBUG] wire - http-outgoing-0 >> “x-csrf-token: fetch[\r][\n]”

2019/05/24 16:58:24:999 CST [DEBUG] wire - http-outgoing-0 >> “Host: hybris.com:443[\r][\n]”

2019/05/24 16:58:24:999 CST [DEBUG] wire - http-outgoing-0 >> “Connection: Keep-Alive[\r][\n]”

2019/05/24 16:58:24:999 CST [DEBUG] wire - http-outgoing-0 >> “User-Agent: Apache-HttpClient/4.5.1 (Java/1.8.0_60)[\r][\n]”

2019/05/24 16:58:24:999 CST [DEBUG] wire - http-outgoing-0 >> “Cookie: SAP_SESSIONID_E4T_100=a-dtZMlUCPrhIHE%3d; sap-usercontext=sap-client=100[\r][\n]”

2019/05/24 16:58:24:999 CST [DEBUG] wire - http-outgoing-0 >> “Accept-Encoding: gzip,deflate[\r][\n]”

2019/05/24 16:58:24:999 CST [DEBUG] wire - http-outgoing-0 >> “[\r][\n]”

2019/05/24 16:58:25:154 CST [DEBUG] wire - http-outgoing-0 << “HTTP/1.1 500 Internal Server Error[\r][\n]”

2019/05/24 16:58:25:154 CST [DEBUG] wire - http-outgoing-0 << “Server: nginx/1.14.2[\r][\n]”

2019/05/24 16:58:25:154 CST [DEBUG] wire - http-outgoing-0 << “Date: Fri, 24 May 2019 08:58:25 GMT[\r][\n]”

2019/05/24 16:58:25:154 CST [DEBUG] wire - http-outgoing-0 << “Content-Type: text/html[\r][\n]”

2019/05/24 16:58:25:154 CST [DEBUG] wire - http-outgoing-0 << “Content-Length: 193[\r][\n]”

2019/05/24 16:58:25:154 CST [DEBUG] wire - http-outgoing-0 << “Connection: close[\r][\n]”

2019/05/24 16:58:25:154 CST [DEBUG] wire - http-outgoing-0 << “[\r][\n]”

2019/05/24 16:58:25:154 CST [DEBUG] wire - http-outgoing-0 << “[\r][\n]”

2019/05/24 16:58:25:155 CST [DEBUG] wire - http-outgoing-0 << “[\r][\n]”

2019/05/24 16:58:25:155 CST [DEBUG] wire - http-outgoing-0 << “[\r][\n]”

2019/05/24 16:58:25:155 CST [DEBUG] wire - http-outgoing-0 << “


500 Internal Server Error

[\r][\n]”

2019/05/24 16:58:25:155 CST [DEBUG] wire - http-outgoing-0 << “

nginx/1.14.2

[\r][\n]”

2019/05/24 16:58:25:155 CST [DEBUG] wire - http-outgoing-0 << “[\r][\n]”

2019/05/24 16:58:25:155 CST [DEBUG] wire - http-outgoing-0 << “[\r][\n]”

2019/05/24 16:58:25:155 CST [DEBUG] headers - http-outgoing-0 << HTTP/1.1 500 Internal Server Error

2019/05/24 16:58:25:155 CST [DEBUG] headers - http-outgoing-0 << Server: nginx/1.14.2

2019/05/24 16:58:25:155 CST [DEBUG] headers - http-outgoing-0 << Date: Fri, 24 May 2019 08:58:25 GMT

2019/05/24 16:58:25:155 CST [DEBUG] headers - http-outgoing-0 << Content-Type: text/html

2019/05/24 16:58:25:155 CST [DEBUG] headers - http-outgoing-0 << Content-Length: 193

2019/05/24 16:58:25:155 CST [DEBUG] headers - http-outgoing-0 << Connection: close

Status code: 500

reason: Internal Server Error


相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
16天前
|
C++
glog --- C++日志库
glog --- C++日志库
|
24天前
|
API 开发工具 C语言
【嵌入式开源库】EasyLogger的使用, 一款轻量级且高性能的日志库
【嵌入式开源库】EasyLogger的使用, 一款轻量级且高性能的日志库
|
30天前
|
XML 运维 监控
【深入探究 C++ 日志库清理策略】glog、log4cplus 和 spdlog 的日志文件管理策略
【深入探究 C++ 日志库清理策略】glog、log4cplus 和 spdlog 的日志文件管理策略
67 0
|
1月前
|
安全 编译器 API
C++系统日志库精选:深入剖析glog与log4cplus,轻松搭建高效日志系统
C++系统日志库精选:深入剖析glog与log4cplus,轻松搭建高效日志系统
106 0
|
1月前
|
存储 SQL 关系型数据库
[MySQL]事务原理之redo log,undo log
[MySQL]事务原理之redo log,undo log
|
1月前
|
存储 数据库 Python
Loguru:Python中强大的日志库
Loguru:Python中强大的日志库
46 2
|
2月前
|
Java Apache
Apache HttpClient 4.5设置超时时间
Apache HttpClient 4.5设置超时时间
|
2月前
|
消息中间件 Kafka Apache
Apache Flink 是一个开源的分布式流处理框架
Apache Flink 是一个开源的分布式流处理框架
482 5
|
1月前
|
消息中间件 API Apache
官宣|阿里巴巴捐赠的 Flink CDC 项目正式加入 Apache 基金会
本文整理自阿里云开源大数据平台徐榜江 (雪尽),关于阿里巴巴捐赠的 Flink CDC 项目正式加入 Apache 基金会。
1414 1
官宣|阿里巴巴捐赠的 Flink CDC 项目正式加入 Apache 基金会
|
1月前
|
SQL Java API
官宣|Apache Flink 1.19 发布公告
Apache Flink PMC(项目管理委员)很高兴地宣布发布 Apache Flink 1.19.0。
1354 1
官宣|Apache Flink 1.19 发布公告

推荐镜像

更多