Django Error Reporting Email when Debug = True
Asked Answered
Y

5

5

Is there a way to get Django to email me error reports even though I have debug set to True?

I didn't see anything in the docs.

Edit:

I'm on Django 1.2 if it matters. No, this isn't a production system.

Yila answered 24/6, 2011 at 12:9 Comment(1)
There is no option for this as far as I know. What you could do perhaps is write your own middleware ("See also" note under the linked paragraph is talking about this)Radiobroadcast
T
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.

Tijuana answered 24/6, 2011 at 15:42 Comment(0)
B
6

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

ADMINS = (('Admin', '[email protected]'),)

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,
        },
    }
}
Bluing answered 10/8, 2014 at 17:39 Comment(0)
T
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.

Tijuana answered 24/6, 2011 at 15:42 Comment(0)
H
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'
        }
    ...
}
Hoicks answered 26/2, 2016 at 21:6 Comment(0)
R
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.

Rhaetian answered 16/5, 2014 at 18:27 Comment(0)
Y
0

Adding the following line to your settings.py file should do the trick.

LOGGING['handlers']['mail_admins']['filters'] = []
Ysabel answered 28/1, 2019 at 19:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.