我做的一个项目基于 bottle + gunicorn 都是遵循标准的 WSGI规范。
现在遇到个需求,就是监控web 是否出错,一旦出错就电子邮件通知。
于是用了一个上午 做了一个这样的middleware,
https://github.com/yueyoum/smoke在使用的时候, 只要你继承 smoke.exceptions.ExceptionMiddleware,重写 handle_exception方法即可。 此方法有个两个位置参数,第一个是 traceback.format_ext(), 第二个是 sys.exc_info()
带有一个例子, 当然在例子里也说明了, 生成环境中不要直接发邮件,应该用消息队列,或者简单的用redis做队列