Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Error Reporting Email when Debug = True

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.

like image 517
Greg Avatar asked Jun 24 '11 12:06

Greg


4 Answers

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,
        },
    }
}
like image 190
John Pang Avatar answered Nov 06 '22 17:11

John Pang


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.

like image 20
Chris Pratt Avatar answered Nov 06 '22 17:11

Chris Pratt


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'
        }
    ...
}
like image 3
Aaron Avatar answered Nov 06 '22 18:11

Aaron


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.

like image 2
Bob Roberts Avatar answered Nov 06 '22 17:11

Bob Roberts