google-app-engine - 如何在 Google App Engine 中全局更改 SDK/Production 中的 Python 日志记录格式?

标签 google-app-engine

如何使用开发或生产服务器中的一些全局设置更改 Google App Engine 中的日志记录格式。当前的日志记录格式在某些情况下不太有用,如上所述,因为不允许定位发出消息的代码。

我想在开发服务器中更改此格式,执行一些显示 init.py 源位置的操作:

DEBUG    2012-10-25 21:09:11,717 __init__.py:135] google, <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fd89988e89bd98859c908d9198d39e9290" rel="noreferrer noopener nofollow">[email protected]</a>

致:

DEBUG    2012-10-25 21:09:11,717 parentDirectory/__init__.py:135] google, <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="265243555266435e474b564a430845494b" rel="noreferrer noopener nofollow">[email protected]</a>

在生产中我想将其更改为:

DEBUG    2012-10-25 21:09:11,717 google, <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6014051314200518010d100c054e030f0d" rel="noreferrer noopener nofollow">[email protected]</a>

致:

DEBUG    2012-10-25 21:09:11,717 parentDirectory/__init__.py:135] google, <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d1a5b4a2a591b4a9b0bca1bdb4ffb2bebc" rel="noreferrer noopener nofollow">[email protected]</a>

请建议一些全局配置加载器 - 如果不可能,我可以将其放入每个脚本中,但我认为这浪费时间 - 如果您知道解决此问题的解决方案,请提供帮助。我搜索了很多页面但没有找到解决方案。

最佳答案

如果您使用webapp2框架,您可以将“全局”代码添加到appengine_config.py中,即automatically included by some AppEngine modules导入。虽然看起来很老套,但向此文件添加记录器配置似乎非常明智,因为它也是一个全局设置。

重新配置记录器的代码可以在 this StackOverflow answer 中找到。 。基本上,您需要导入日志记录,并侵入由 AppEngine 本身预先配置的记录器:

logging.getLogger().handlers[0].setFormatter(fr)

关于google-app-engine - 如何在 Google App Engine 中全局更改 SDK/Production 中的 Python 日志记录格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13075877/

相关文章:

java - 在 App Engine 数据存储区查看器中编辑日期字段

ios - 使用 iOS 客户端库将自定义 header 添加到 iOS (Swift) 中的 Cloud Endpoints 调用

java - 最喜欢的开源 Google App Engine 应用(Java 或 Python)

Python AppEngine - 如何在 app.yaml 中传递查询字符串

python - __call__() 缺少 1 个必需的位置参数 : 'send' FastAPI on App Engine

python - 如果未提供 Content-Length,则使用 python 正确下载文件

java - 如何在 Google 应用引擎上使用 Session

python - Google App Engine : app. yaml 与 python 代码中的身份验证

java - Webhook 与发布者和订阅者

python-2.7 - 特定服务/版本谷歌应用引擎的 Cron