设置中的我的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
答案 0 :(得分:7)
你必须写,
logging.handlers.TimedRotatingFileHandler
因为TimedRotatingFileHandler
是日志记录处理程序包的一部分。