Can I make Python output exceptions in one line / via logging?

前端 未结 3 1200
南方客
南方客 2021-01-17 16:18

I am using AWS and use AWS cloudwatch to view logs. While things should not break on AWS, they could. I just had such a case. Then I searched for Traceback and

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-17 16:46

    A slight variation: If you run a Flask application, you can do this:

    @app.errorhandler(Exception)
    def exception_logger(error):
        """Log the exception."""
        logger.exception(str(error))
        return str(error)
    

提交回复
热议问题