flask
flask copied to clipboard
Flask exception logging has a catch-22
Flask only logs in debug mode.
handle_exception raises an exception in debug, else returns an InternalServerError and logs the exception.
Except that by default, it can't log the exception because it's in debug.
This is mostly just an annoyance as long as you are running with run_simple, as the Werkzueg debugger will log the exception that got re-raised in handle_exception and provide you with a great debugging interface. However, if you switch to a different WSGI engine, you end up with no way to see a traceback.
In app.py handle_exception:
if self.propagate_exceptions:
# if we want to repropagate the exception, we can attempt to
# raise it with the whole traceback in case we can do that
# (the function was actually called from the except part)
# otherwise, we just raise the error again
if exc_value is e:
raise exc_type, exc_value, tb
else:
raise e
self.log_exception((exc_type, exc_value, tb))
if handler is None:
return InternalServerError()
return handler(e)