I have the following logging config set up in Django 1.8:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': normpath(join(DJANGO_ROOT, '../../logs', 'django.log')),
},
},
'loggers': {
'': {
'handlers': ['file'],
'propagate': True,
'level': 'DEBUG',
},
},
}
Moreover, I'm also logging the stdout and stderr of gunicorn into two separate files via supervisord.
My problem is that not all errors are showing up in Django logs. For example, there is a case when I had a simple .get()
query in a model's save function, which raised a DoesNotExist
exception in the admin page. This exception did not show up at all in any Django log, all I could see was the 500 in the nginx log for a POST request.
When I tried with debug mode in local machine, it produced the detailed error page, but what if I couldn't reproduce a bug in a local machine?
Why are 500 errors silently disappearing in Django and how can I fix it?
// I know that Sentry is able to report such exception errors, I'm looking for a way which doesn't involve using an external service.
I debugged the case, it was a combination of two things:
SERVER_EMAIL
, Django sends admin emails fromroot@localhost
. The SMTP provider I'm using (Mandrill) silently blocks all emails from such address, thus I never got the emails, nor any log at Mandrill.Solution was to specify
SERVER_EMAIL
to a real address and test admin email sending usingmail_admins()
.django.security
anddjango.request
loggers are set not to propagate by default, thus my root logger''
did not catch them.Solution was to re-specify them and set propagate to True. This way they both send emails and are visible in the log files as well.
My working logger configuration is the following: