On error email admins (#1336)

* add option to e-mail errors to ADMINS

Set ADMINS to a list of all the people who get code error notifications.
When DEBUG=False Django emails these people the details of exceptions
raised in the request/response cycle.

* don't choke if settings.py contains utf8 characters
This commit is contained in:
Andrew Fyfe
2017-12-21 17:52:54 +01:00
committed by Antoine Nguyen
parent 47154039e0
commit 168743f74b
2 changed files with 22 additions and 1 deletions
+2 -1
View File
@@ -4,6 +4,7 @@
from __future__ import unicode_literals, print_function
import codecs
import getpass
import os
import shutil
@@ -253,7 +254,7 @@ class DeployCommand(Command):
'extra_settings': extra_settings
}
)
with open("%s/settings.py" % path, "w") as fp:
with codecs.open("%s/settings.py" % path, "w", "utf-8") as fp:
fp.write(tpl)
shutil.copyfile(
"%s/urls.py.tpl" % self._templates_dir, "%s/urls.py" % path
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""
Django settings for {{ name }} project.
@@ -39,6 +40,15 @@ ALLOWED_HOSTS = [
SITE_ID = 1
# A list of all the people who get code error notifications. When DEBUG=False
# and a view raises an exception, Django will email these people with the full
# exception information.
# See https://docs.djangoproject.com/en/dev/ref/settings/#admins
#ADMINS = [('Administrator', 'admin@example.net')]
# The email address that error messages come from, such as those sent to ADMINS
#SERVER_EMAIL = 'webmaster@example.net'
# Security settings
X_FRAME_OPTIONS = "SAMEORIGIN"
@@ -252,6 +262,11 @@ LOGGING = {
},
},
'handlers': {
'mail-admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'include_html': True
},
'syslog-auth': {
'class': 'logging.handlers.SysLogHandler',
'facility': SysLogHandler.LOG_AUTH,
@@ -262,6 +277,11 @@ LOGGING = {
}
},
'loggers': {
'django': {
'handlers': ['mail-admins'],
'level': 'ERROR',
'propagate': False
},
'modoboa.auth': {
'handlers': ['syslog-auth', 'modoboa'],
'level': 'INFO',