TOC

Requests 的日志配置

import http.client
import logging

import requests

LOG_LEVEL = logging.DEBUG
LOG_FORMAT = '%(asctime)s [%(thread)s] [%(name)s:%(funcName)s#%(lineno)d] %(levelname)s %(message)s'
logging.basicConfig(level=LOG_LEVEL, format=LOG_FORMAT)

LOG_HTTP = logging.getLogger("http.client")

def httpclient_log(*args):
    LOG_HTTP.log(logging.DEBUG, " ".join(args))

http.client.print = httpclient_log
http.client.HTTPConnection.debuglevel = 1