【问题标题】:Django logging with dictConfig cannot find "logging" module使用 dictConfig 进行日志记录的 Django 找不到“日志记录”模块
【发布时间】:2011-10-21 03:09:49
【问题描述】:

我在设置中的 LOGGING 指令设置为:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'default': {
            'format': '[%(asctime)s] %(levelname)s::(%(process)d %(thread)d)::%(module)s - %(message)s'
        },
    },
    'handlers': {
        'file_handler': {
            'level': 'DEBUG',
            'formatter':'default',
            'class': 'logging.TimedRotatingFileHandler',
            'filename':'Project_log',
            'when':'midnight',
            'interval':1
        },
    },
    'loggers': {
        'django.request': {
            'handlers': ['file_handler'],
            'level': 'DEBUG',
            'propagate': True,
        },
    }
}

根据文档示例,处理程序的类设置为 logging.HandlerName:https://docs.djangoproject.com/en/dev/topics/logging/

但我收到以下错误:

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/config.py", line 776, in dictConfig
    dictConfigClass(config).configure()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/config.py",     line 575, in configure
'%r: %s' % (name, e))
ValueError: Unable to configure handler 'file_handler': Cannot resolve 'logging.TimedRotatingFileHandler': No module named TimedRotatingFileHandler

【问题讨论】:

    标签: python django logging python-2.6 django-1.3


    【解决方案1】:

    你必须写,

    logging.handlers.TimedRotatingFileHandler
    

    因为TimedRotatingFileHandler 是日志处理程序包的一部分。

    【讨论】:

    • 我刚刚签入了 ipython,如果您只需要找出您需要导入的确切内容,那就太棒了
    • 应该是logging.handlers.TimedRotatingFileHandler
    猜你喜欢
    • 2017-06-04
    • 1970-01-01
    • 1970-01-01
    • 2011-08-18
    • 2020-11-07
    • 1970-01-01
    • 2016-08-15
    • 1970-01-01
    相关资源
    最近更新 更多