I have a site built in Django.
When an error occurs on the production site, Django automatically sends a stack trace to the email addresses listed in the ADMINS list in settings.py.
I would like this stack trace to include local variables for each stack frame (like the standard stack trace does when the site is in debug mode).
Any ideas?
Thanks!
When DEBUG is False , Django will email the users listed in the ADMINS setting whenever your code raises an unhandled exception and results in an internal server error (strictly speaking, for any response with an HTTP status code of 500 or greater). This gives the administrators immediate notification of any errors.
As first step, enable DEBUG mode in Django settings module to see if that fixes the issue or at least causes a description of the error in the browser. It is quite common to get a 500 error response delivered back from Django with no record of the exception being logged.
It's really simple to set this up. Just put 'include_html': True
in the logging config of whichever handler is sending error emails for you.
For example (this is the default logging handler aside from the "include_html" line):
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false',],
'class': 'django.utils.log.AdminEmailHandler',
'include_html': True
}
}
This includes an html attachment in the error email with the contents of the error page you get when DEBUG=True. The Django docs have a few more details and a note about security.
You could also look at setting up a logging handler which uses subclasses of django.utils.log.AdminEmailHandler
and django.views.debug.ExceptionReporter
if you need to customize things a lot more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With