如何使用开发或生产服务器中的一些全局设置更改 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/