简体   繁体   English

Google App Engine错误未显示在使用Flask的StackDriver错误报告中

[英]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: 结果如下:

  • The errors show up in the Google App Engine overview: 错误显示在Google App Engine概述中: 所有Google App Engine错误
  • Both are visible in the logs: 两者都在日志中可见: 日志中可见错误
  • But nothing shows up in StackDriver Error Reporting: 但StackDriver错误报告中没有显示任何内容: StackDriver错误报告中没有错误

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.

相关问题 在App Engine Standard python中使用Google Stackdriver日志时出错 - Error using Google Stackdriver Logging in App Engine Standard python Google Stackdriver使用Redis队列登录App Engine(Python) - Google Stackdriver logging in App Engine (Python) using Redis queue 将 Google App Engine 与 Flask 和 Flask-restplus 一起使用时出现 404 错误 - 404 error when using Google App Engine with flask and flask-restplus Flask应用程序上的Google StackDriver登录-默认Flask记录器之间的区别? - Google StackDriver Logging on Flask App - Difference between default Flask logger? Google App Engine上的Flask应用程序-显示数据库对象 - Flask application on google app engine - Showing database object 将 Flask 应用程序部署到 Google App Engine 时出现问题 - 错误消息 - Issues with deploying Flask app to Google App Engine - Error Messages 使用Docker在Google App Engine Flex上进行烧瓶应用部署 - Flask app deployment on Google App Engine Flex using Docker Google App Engine数据存储区Jinja2查询未显示 - Google App Engine Datastore Jinja2 Query Not showing up Google App Engine Flask 413请求实体太大错误 - Google App Engine Flask 413 Request Entity Too Large Error App Engine启动错误 - App Engine Start Up Errors
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM