Skip to content

Override Flask.log_exception()

Rolf Krahl requested to merge log-exception into master

Override method log_exception() in hzb_rdm.web.flask.Flask, implementing the following changes with respect to the inherited method:

  • log with level CRITICAL rather than ERROR,
  • log class and message of the exception rather then the somewhat meaningless "Exception on {request.path} [{request.method}]".

This method is called in Flask on unhandled exceptions, the default log handler will emit a stack trace to stderr. I'd assume an unhandled exception is always the result of a bug in the web service script (either it is caused by a bug in the first place or the script fails to properly handle and report defective input). The caller of the web service script will see an "Internal server error". If this happens in production, it should always be considered a critical condition. Note that while the class and message of the exception will also be included as the last line of stack trace, some logging handlers suppress that trace, so this information need to be included in the log message.

Edited by Rolf Krahl

Merge request reports

Loading