[英]Google App Engine Errors not showing up in StackDriver Error Reporting using Flask
I'm using Google App Engine standard environment to host a python-flask-application and I'm having issues to get the errors to show up in StackDriver Error Reporting. 我正在使用Google App Engine标准环境来托管python-flask-application,而我遇到的问题是在StackDriver错误报告中显示错误。 By default Google App Engine should log errors to StackDriver Error Reporting, but it doesn't.
默认情况下,Google App Engine会将错误记录到StackDriver错误报告中,但事实并非如此。
I've had errors before that showed up in StackDriver Error Reporting, but I can't reproduce that. 我之前在StackDriver错误报告中出现过错误,但我无法重现。 The errors seem to go straight to the Server-Errors section and not to the Application-Errors.
这些错误似乎直接发生在Server-Errors部分,而不是Application-Errors。 But it seems logical to me that both are logged in StackDriver Error Reporting.
但对我来说,两者都记录在StackDriver错误报告中似乎是合乎逻辑的。
I did some debugging in order to get it working using routes /error
and /500
. 我做了一些调试,以使它使用routes
/error
和/500
。 The result was the following: 结果如下:
Would anyone have an idea why this is the case? 有人会知道为什么会这样吗?
UPDATE: I found that using the flask.logger
seems to be the problem. 更新:我发现使用
flask.logger
似乎是个问题。 Using logging
works ok and ends up in StackDriver Error Reporting (except for some formatting issues). 使用
logging
工作正常并最终在StackDriver错误报告中(除了一些格式问题)。 Both do end up in the logger though. 两者最终都会在记录器中结束。 I am using a
logging.StreamHandler
to register to flask.logger
using addHandler
. 我使用的是
logging.StreamHandler
注册到flask.logger
使用addHandler
。 My best guess is that there is something wrong with the formatting of the logging.StreamHandler
. 我最好的猜测是
logging.StreamHandler
的格式有问题。 Investigating further. 进一步调查。
After some digging and debugging using the Google App Engine SDK I found that there is a logging-handler for GAE: 在使用Google App Engine SDK进行一些挖掘和调试之后,我发现GAE有一个日志记录处理程序:
google.appengine.api.app_logging.AppLogsHandler
Google App Engine registers one to logging
, but not to flask.logger
. Google App Engine
flask.logger
一个注册到logging
,但不会注册到flask.logger
。 So if you use app.logger.error(my_error)
for example, it won't register to StackDriver Error Reporting. 因此,如果您使用
app.logger.error(my_error)
,它将不会注册到StackDriver错误报告。
Now I register one manually which fixes the issue: 现在我手动注册一个修复问题:
from google.appengine.api.app_logging import AppLogsHandler
app.logger.addHandler(AppLogsHandler())
app.logger.error(my_error)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.