在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.
更多推荐
发布评论