在我的django应用程序中,我使用库requests
。在头文件中,我使用请求:
try:
# for Python 3
from http.client import HTTPConnection
except ImportError:
from httplib import HTTPConnection
if settings.DEBUG:
HTTPConnection.debuglevel = 1
logging.getLogger("requests.packages.urllib3")
logging.getLogger("requests.packages.urllib3.connectionpool")
在django设置中:
LOGGING = {
handlers: {
'requests.packages.urllib3': {
'handler': ['console'],
'propagate': False,
'level': LOGLEVEL,
},
'requests.packages.urllib3.connectionpool': {
'handler': ['console'],
'propagate': False,
'level': LOGLEVEL,
}
}
}
在控制台中我收到消息:
No handlers could be found for logger "requests.packages.urllib3.connectionpool"
答案 0 :(得分:1)
您在settings.py
文件中错误地使用了处理程序。
您应该指定要在package
词典的loggers
子项中登录的LOGGING
。
尝试这样的事情:
LOGGING = {
"formatters": {
"verbose": {
"format": "%(asctime)s %(levelname)s:%(name)s:L%(lineno)s: %(message)s"
}
},
"handlers": {
"console": {
"level": "DEBUG",
"formatter": "verbose",
"class": "logging.StreamHandler",
},
},
"loggers": {
"requests": {
"handlers": ["console"],
"level": "DEBUG",
"propagate": True,
},
"requests.packages.urllib3.connectionpool": {
"handlers": ["console"],
"level": "DEBUG",
"propagate": True,
},
}