In core/handlers/base.py, handle_uncaught_exception() does:
if settings.DEBUG:
from django.views import debug
return debug.technical_500_response(request, *exc_info)
logger.error('Internal Server Error: %s' % request.path,
exc_info=exc_info,
extra={
'status_code': 500,
'request':request
}
)
Wouldn't it make more sense to always log the exception? As it stands now, it's an either/or deal. If DEBUG, produce the debug page and don't log. If not DEBUG, log and produce a normal 500 page.
I ended up writing my own process_exception() middleware to log stack traces for all uncaught exceptions. This was fine in development, but in production, with DEBUG = False, I get *two* stacks in my log files for every exception (one from my hander, another from the code above). This all seems silly. It would be so much simpler (and obvious) if handle_uncaught_exception() always logged, regardless of which flavor of response it's going to produce.