【原创】Python 关闭某些log输出,关闭request info/debug输出
(2014-11-17 20:05:10)
标签:
pythonloggingrequestconnectionpoolinfo |
分类: python |
使用requests的时候,总是会输入多余INFO日志
[2014-11-17 20:04:38,664](DEBUG)root :
开始下载URL:http://www.baidu.com/
[2014-11-17
20:04:38,753](INFO)requests.packages.urllib3.connectionpool :
Starting new HTTP connection (1): www.baidu.com
[2014-11-17
20:04:38,858](DEBUG)requests.packages.urllib3.connectionpool : "GET
/ HTTP/1.1" 200 16779
怎么关闭呢?
import logging
logging.getLogger("requests").setLevel(logging.WARNING)
怎么打开详尽日志呢?
import requests
import logging
import httplib
httplib.HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
requests .get('http://httpbin.org/headers')
参见stackoverflow:How do I disable log messages from the Requests
library?