用dictConfig记录的Django无法找到“logging”模块

时间:2011-08-05 18:50:03

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

设置中的我的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

1 个答案:

答案 0 :(得分:7)

你必须写,

logging.handlers.TimedRotatingFileHandler

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