ypr*_*rez 7 python django logging django-email django-settings
我在我的Django应用程序中使用自定义电子邮件后端(在本例中为CeleryEmailBackend):
EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'
Run Code Online (Sandbox Code Playgroud)
我的日志配置:
LOGGING = {
# ...
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler',
},
# ...
}
Run Code Online (Sandbox Code Playgroud)
管理员错误电子邮件也会由同一电子邮件后端发送.
因此,如果电子邮件后端出现问题(例如Celery未运行).然后我将不会收到服务器错误电子邮件.
有没有办法AdminEmailHandler使用自定义电子邮件后端?
It's possible, but in django 1.6, quote from documentation:
By setting the email_backend argument of AdminEmailHandler, the email backend that is being used by the handler can be overridden, like this:
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'email_backend': 'django.core.mail.backends.filebased.EmailBackend',
}
},
Run Code Online (Sandbox Code Playgroud)
If you don't want to upgrade (since 1.6 is not stable, for example), consider making a custom email handler based on AdminEmailHandler. Should not be hard, because the actual implementation of this new feature is pretty straight-forward and clean (see pull-request).
或者,您实际上可以AdminEmailHandler从django 1.6中提取整个类,并将其用作自定义电子邮件处理程序.
| 归档时间: |
|
| 查看次数: |
1223 次 |
| 最近记录: |