Skip to content

Commit

Permalink
Merge pull request #555 from rcpch/mbarton/email-admins-on-error
Browse files Browse the repository at this point in the history
Email admins on error
  • Loading branch information
mbarton authored Feb 6, 2025
2 parents 6f0e077 + 55f67c7 commit 4cee828
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions envs/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ LOCAL_DEV_ADMIN_PASSWORD="devp@ssword12345"

EMAIL_DEFAULT_FROM_EMAIL = "[email protected]"

# Error reporting when DEBUG=False. Format: <name>:<email>,<name>:<email>...
# ADMINS="admin:[email protected]"
19 changes: 14 additions & 5 deletions project/logging_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Define the default django logger settings
django_loggers = {
logger_name: {
"handlers": ["django_console", "npda_logfile"],
"handlers": ["django_console", "npda_logfile", "mail_admins"],
"level": CONSOLE_DJANGO_LOG_LEVEL,
"propagate": False,
"formatter": "simple_django",
Expand All @@ -32,7 +32,11 @@
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"filters": {},
"filters": {
"require_debug_false": {
"()": "django.utils.log.RequireDebugFalse",
},
},
"formatters": {
"django.server": {
"()": "django.utils.log.ServerFormatter",
Expand Down Expand Up @@ -100,20 +104,25 @@
"backupCount": 10,
"formatter": "file",
},
"mail_admins": {
"level": "ERROR",
"filters": ["require_debug_false"],
"class": "django.utils.log.AdminEmailHandler",
},
},
"loggers": {
"django": {
"handlers": ["django_console", "npda_logfile"],
"handlers": ["django_console", "npda_logfile", "mail_admins"],
"level": CONSOLE_DJANGO_LOG_LEVEL,
},
**django_loggers, # this injects the default django logger settings defined above
"project": {
"handlers": ["npda_console", "npda_logfile"],
"handlers": ["npda_console", "npda_logfile", "mail_admins"],
"propagate": False,
"level": CONSOLE_LOG_LEVEL,
},
"two_factor": {
"handlers": ["npda_console", "npda_logfile"],
"handlers": ["npda_console", "npda_logfile", "mail_admins"],
},
},
}
Expand Down
5 changes: 5 additions & 0 deletions project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@

# EMAIL SETTINGS (SMTP)
DEFAULT_FROM_EMAIL = os.environ.get("EMAIL_DEFAULT_FROM_EMAIL")
SERVER_EMAIL = os.environ.get("EMAIL_DEFAULT_FROM_EMAIL")
SMTP_EMAIL_ENABLED = os.getenv("SMTP_EMAIL_ENABLED", "False") == "True"
logger.info("SMTP_EMAIL_ENABLED: %s", SMTP_EMAIL_ENABLED)
if SMTP_EMAIL_ENABLED is True:
Expand All @@ -291,6 +292,10 @@

SITE_CONTACT_EMAIL = os.environ.get("SITE_CONTACT_EMAIL")

ADMINS = os.environ.get("ADMINS", '')
if ADMINS:
ADMINS = [e.split(":") for e in ADMINS.split(",")]

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

Expand Down

0 comments on commit 4cee828

Please sign in to comment.