防止Python日志中错误的重复输出
我在我的 Python LOGGING
配置中遇到了异常和错误的日志输出重复的问题。这种情况是可以理解的,因为我的配置是这样的:
LOGGING = {
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'sentry': {
'level': 'WARNING',
'class': 'raven.contrib.django.handlers.SentryHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'verbose'
},
},
'root': {
'level': 'ERROR', # Give me errors only
'handlers': ['mail_admins', 'sentry', 'console'],
},
'apps.order_shipping': {
# This module needs extra debugging, but now ERROR is duplicated
'handlers': ['console'],
'level': 'DEBUG',
},
}
我该如何更好地实现这个呢?我想为某些模块开启详细日志,但又不想让错误信息重复出现。
1 个回答
3
将propagate设置为False
:
{
# ...
'apps.order_shipping': {
# This module needs extra debugging, but now ERROR is duplicated
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
}