zoukankan      html  css  js  c++  java
  • 解决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)

    【版权所有@Sevck 博客地址http://www.cnblogs.com/sevck】 可以转载,注明出处.
  • 相关阅读:
    微服务-01
    Java 类加载机制
    数据库&缓存
    JVM&GC
    MyBatis
    spring
    mysql技术内幕-读书笔记
    mysql CookBook -读书笔记
    从根上理解mysql-读书笔记
    高性能mysql-读书笔记
  • 原文地址:https://www.cnblogs.com/sevck/p/14818985.html
Copyright © 2011-2022 走看看