Django错误电子邮件报告未发送 [英] Django error email report not being sent
问题描述
我正在努力与django(1.5.1)错误的电子邮件报告没有发送。
I have struggling with django(1.5.1) error email reports not being sent.
这里是我的conf设置用于gmail
here is my conf settings to use with gmail
DEFAULT_FROM_EMAIL = 'server@example.com'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'server@example.com'
EMAIL_HOST_PASSWORD = 'passs'
EMAIL_USE_TLS = True
SERVER_EMAIL = 'server@example.com'
ADMINS = (
('Adam Min', 'adam@example.com'),
)
如果我添加 MANAGERS = ADMINS
然后我收到404的
的电子邮件,但没有 MANAGERS
设置我根本没有收到。
If I add MANAGERS = ADMINS
then I receive emails for 404's
but without MANAGERS
setting I receive nothing at all.
我创建了一个错误的URL,以便我可以测试。
I have created a buggy url so I can test this.
此外,我发现这个类似的Q Django通过电子邮件发送错误但是没有帮助我。
Also I found this similar Q Django emailing on errors but it didn't help me.
编辑:
也在配置我有 DEBUG = False
和此
also in config I have DEBUG = False
and this
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s [%(asctime)s] %(module)s %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse',
}
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'file': {
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'verbose',
'filename': '/var/www/logs/ibiddjango.log',
'maxBytes': 1024000,
'backupCount': 3,
},
'sql': {
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'verbose',
'filename': '/var/www/logs/sql.log',
'maxBytes': 102400,
'backupCount': 3,
},
'commands': {
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'verbose',
'filename': '/var/www/logs/commands.log',
'maxBytes': 10240,
'backupCount': 3,
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django': {
'handlers': ['file', 'console'],
'propagate': True,
'level': 'DEBUG',
},
'django.db.backends': {
'handlers': ['sql', 'console'],
'propagate': False,
'level': 'WARNING',
},
'scheduling': {
'handlers': ['commands', 'console'],
'propagate': True,
'level': 'DEBUG',
},
}
}
我缺少什么?
推荐答案
似乎您的问题出在您的日志配置中:在 settings.py
LOGGING
:
it seems that your problem is in your logging configuration: in settings.py
LOGGING
:
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
}
此配置表示 mail_admins
处理程序仅在中工作DEBUG = False
因为使用过滤器。
如果您尝试使用模式调试错误,或者您可以在调试模式下激活此处理程序,只需对过滤器进行注释:
This config indicate that mail_admins
handler work only in DEBUG = False
because the filter used.
If you try with mode debug false or you can activate this handler in debug mode just comment the filters:
'handlers': {
'mail_admins': {
'level': 'ERROR',
#'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
}
编辑:
您的配置不调用 mail_admins
处理程序。将它添加到django记录器,如下所示:
Your configuration doesn't call mail_admins
handler. Add it to the django logger like this:
'loggers': {
'django': {
'handlers': ['file', 'console', 'mail_admins',],
'propagate': True,
'level': 'DEBUG',
},
这篇关于Django错误电子邮件报告未发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!