The Python Oracle

Django Error Reporting Email when Debug = True

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT


Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5 Looping

--

Chapters
00:00 Django Error Reporting Email When Debug = True
00:22 Accepted Answer Score 4
00:50 Answer 2 Score 2
01:11 Answer 3 Score 6
01:33 Answer 4 Score 3
01:53 Thank you

--

Full question
https://stackoverflow.com/questions/6467...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #django #djangoemail #djangoerrors

#avk47



ANSWER 1

Score 6


If you only have one email, make sure you have a comma in the list:

ADMINS = (('Admin', 'admin@my-domain.com'),)

I tried these and seems work:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}



ACCEPTED ANSWER

Score 4


You might want to look at django-sentry. It's really designed for use in production, but it has TESTING setting to make it work when DEBUG=True as well. It might actually send out emails at that point, too -- haven't tested that myself, but it'll at least keep a log of errors that you can view at any time from any web-enabled device.

Besides, when you do eventually go to production, it'll be a life-saver.




ANSWER 3

Score 3


Just to expand on Bob Roberts answer a bit, I found the default logging configuration in django.utils.log. You can just copy and paste it to your settings, name it LOGGING, and change the line:

# settings.py:
# copied from django.utils.log import DEFAULT_LOGGING
LOGGING = {
    ...
        'mail_admins': {
            'level': 'ERROR',
            # emails for all errors
            #'filters': ['require_debug_false'],
            'filters': [],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    ...
}



ANSWER 4

Score 2


I believe you can achieve that by specifying an empty list to the filters associated with your AdminEmailHandler defined in your settings.py.

For instance:

'mail_admins': {
    'level': 'ERROR',
    'class': 'django.utils.log.AdminEmailHandler',
    'filters': []
}

By default the filters for this class would be a django.utils.log.RequireDebugFalse.