我有一个Django项目,其中包含以下日志记录配置:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': 'LEVEL:%(levelname)s TIME:%(asctime)s MODULE:%(module)s LINE:%(lineno)d PROCESS:%(process)d THREAD:%(thread)d MESSAGE:%(message)s'
}},
'handlers': {
# Include the default Django email handler for errors
# This is what you'd get without configuring logging at all.
'mail_admins': {
'class': 'django.utils.log.AdminEmailHandler',
'level': 'ERROR',
# But the emails are plain text by default - HTML is nicer
'include_html': True,
'filters : [],
},
# Log to a text file that can be rotated by logrotate
'logfile': {
'class': 'logging.handlers.WatchedFileHandler',
'filename': '/[more stuff here]/statistics/logs/django.log',
'formatter' : 'verbose'
'filters : [],
},
},
'loggers': {
# Again, default Django configuration to email unhandled exceptions
'django.request': {
'handlers': ['mail_admins','logfile'],
'level': 'ERROR',
'propagate': True,
},
# Might as well log any errors anywhere else in Django
'django': {
'handlers': ['logfile','mail_admins'],
'level': 'ERROR',
'propagate': True,
},
},
}
如果include_html
设置为True
我没有收到任何错误的电子邮件,并且处理程序甚至没有打开与SMTP服务器的连接(我使用Python SMTP服务器验证了这一点)替换)。设置include_html = False
时一切正常,所以我认为这是一个错误格式的错误消息或编码问题。
如何在记录期间检索 AdminEMailHandler 生成的异常?现在处理程序只是静默失败,这对于记录严重错误的处理程序来说非常糟糕。