无法找到记录器请求的处理程序.packages.urllib3.connectionpool

时间:2016-01-27 17:22:26

标签: python django logging

在我的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"

1 个答案:

答案 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,
        },
    }