解決requests的logging日志打印大量INFO,DEBUG日志


在項目中使用logging記錄日志文件,當此類使用了requests,查看log大量request請求存在在日志中。

Thu, 27 May 2021 17:36:11 connectionpool.py[line:203] INFO Starting new HTTP connection (1): xxx.xxx.xxxx.cn
Thu, 27 May 2021 17:36:11 connectionpool.py[line:383] DEBUG "POST //xxxx/auth/identity/connect/token HTTP/1.1" 200 None
Thu, 27 May 2021 17:36:11 connectionpool.py[line:203] INFO Starting new HTTP connection (1): xx.xxx.xxxx.cn
Thu, 27 May 2021 17:36:11 connectionpool.py[line:383] DEBUG "GET //xxxx/xx/scans/1000033 HTTP/1.1" 200 1315

導致大量無用寫入。

requests官方文檔中說明的各種階段的日志等級.

INFO: New connections (HTTP or HTTPS)
INFO: Dropped connections
INFO: Redirects
WARN: Connection pool full (if this happens often increase the connection pool size)
WARN: Retrying the connection
DEBUG: Connection details: method, path, HTTP version, status code and response length

可以使用 logger = logging.getLogger(__name__) ,對於調用方可以使用getLogger獲取和配置對象的日志.  比如, logging.getLogger("requests").setLevel(logging.INFO)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM