See https://flask.palletsprojects.com/en/2.0.x/logging/ for details. Also, use the `traceback` module.