Opened 3 years ago

Closed 3 years ago

#33624 closed Uncategorized (invalid)

Only disable console logging when ADMINS is set

Reported by: Alex Dehnert Owned by:
Component: Error reporting Version: 4.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The current logging defaults are:

  • If DEBUG=True, log to console
  • If DEBUG=False, use AdminEmailHandler

In practice, I think this means if you set DEBUG=False and don't touch anything else, errors just vanish -- ADMINS defaults to [], so the emails don't actually go anywhere. The stock settings.py doesn't even mention ADMINS as something you might want to set, so this mistake seems very easy to make. (Also, empirically I made it.)

Perhaps the logging defaults should be:

  • If DEBUG=True or ADMINS is empty, log to console
  • If DEBUG=False and ADMINS is non-empty, send emails

(Alternatively, ADMINS could be added to the settings.py template, and perhaps a system check could be added to verify it's populated?)

(I suspect the patch here is easy, but it seems like it requires a ~design decision that it's desirable.)

Change History (1)

comment:1 by Carlton Gibson, 3 years ago

Resolution: invalid
Status: newclosed

HI Alex.

... and ADMINS is non-empty ...

The mail_admins function, used by AdminEmailHandler already includes a check for this:

def mail_admins(
    subject, message, fail_silently=False, connection=None, html_message=None
):
    """Send a message to the admins, as defined by the ADMINS setting."""
    if not settings.ADMINS:
        return

Src

The ADMINS setting is discussed multiple times in the docs, but explicitly in the deployment checklist, and error reporting documentation. For me, I think that sufficient really.

Note: See TracTickets for help on using tickets.
Back to Top