【发布时间】:2013-12-06 18:29:20
【问题描述】:
我在 Django 1.5 中有一个项目,并且有一个用于调试、信息和错误的日志记录处理程序。
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'console':{
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'file_debug':{
'level':'DEBUG',
'class':'logging.handlers.TimedRotatingFileHandler',
'filename': os.path.join(SITE_ROOT, '..','logs','DEBUG.log'),
'when':'midnight',
'interval':1,
'backupCount': 4,
'formatter':'simple',
'filters':['require_debug_true']
},
'file_info':{
'level':'INFO',
'class':'logging.handlers.TimedRotatingFileHandler',
'filename': os.path.join(SITE_ROOT, '..','logs','INFO.log'),
'when':'midnight',
'interval':1,
'backupCount': 4,
'formatter':'simple',
},
'file_error':{
'level':'ERROR',
'class':'logging.handlers.TimedRotatingFileHandler',
'filename': os.path.join(SITE_ROOT, '..','logs','ERROR.log'),
'when':'midnight',
'interval':1,
'backupCount': 4,
'formatter':'simple',
},
},
'loggers': {
'django.request':{
'handlers': ['console'],
'propagate': False,
'level': 'DEBUG',
},
},
}
但是我想要一个只包含特定内容的日志文件,我不希望在其中打印任何错误。我认为使用 CRITICAL 级别可能会解决我的问题,但由于我的日志中的信息仅用于报告信息,因此具有高于 CRITICAL 的通用级别可能会变得很少,例如:
'file_report':{
'level':'REPORT',
'class':'logging.handlers.TimedRotatingFileHandler',
'filename': os.path.join(SITE_ROOT, '..','logs','REPORT.log'),
'when':'midnight',
'interval':1,
'backupCount': 4,
'formatter':'simple',
},
我的案例的最佳做法是什么?
【问题讨论】: