在Google App Engine中记录完整的回溯以获取烧瓶应用(Logging full tracebacks in Google App Engine for a flask app)

编程入门 行业动态 更新时间:2024-10-28 21:18:59
在Google App Engine中记录完整的回溯以获取烧瓶应用(Logging full tracebacks in Google App Engine for a flask app)

出于某种原因,每当我的Flask应用程序引发异常时,我只会在App Engine日志中看到堆栈跟踪的第一行。 在Google App Engine中为烧瓶应用记录完整追溯的正确方法是什么? 我对此进行了修改,这显然是一个黑客攻击,尽管它通过将它们写入stderr来完成将回溯引入GAE日志的工作:

class TraceHandler(Handler): """We capture unhandled exceptions within applicatoin requests, and write the trace to stdout. This puts the trace in the GAE application logs.""" def __init__(self): """ Initialize the handler. """ Handler.__init__(self) def emit(self, record): import sys import traceback ei = sys.exc_info() try: exception = ''.join(traceback.format_exception(ei[0], ei[1], ei[2], None)) es = exception.strip() if es and es != 'None': sys.stderr.write(exception) except IOError: pass # see issue 5971 finally: del ei th = TraceHandler() app.logger.addHandler(th)

For some reason, whenever my Flask application raises an exception, I only see the first line of the stack trace in the App Engine logs. What is the right way to log full tracebacks in Google App Engine for a flask app? I trued this, which is obviously a hack, though it does do the job of getting the traceback into the GAE logs through writing them to stderr:

class TraceHandler(Handler): """We capture unhandled exceptions within applicatoin requests, and write the trace to stdout. This puts the trace in the GAE application logs.""" def __init__(self): """ Initialize the handler. """ Handler.__init__(self) def emit(self, record): import sys import traceback ei = sys.exc_info() try: exception = ''.join(traceback.format_exception(ei[0], ei[1], ei[2], None)) es = exception.strip() if es and es != 'None': sys.stderr.write(exception) except IOError: pass # see issue 5971 finally: del ei th = TraceHandler() app.logger.addHandler(th)

最满意答案

实际上,多行回溯实际上出现在GAE日志中。 要超越第一行,您必须按小加号图标。

Multi-line tracebacks actually do appear in the GAE logs. To see beyond the first line you have to press the little plus icon.

更多推荐

本文发布于:2023-07-28 12:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1305226.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:烧瓶   完整   App   Engine   Google

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!