python - GAE 灵活和 Stackriver 使用 python 记录严重性级别
问题描述
我正在谷歌灵活应用引擎中运行 python 3 应用程序。我正在使用默认的 python 根记录器,并希望能够查看此图像中的日志级别。
使用 gunicorn 在 GAE 中部署具有以下日志配置的应用程序时:
import logging
logging.basicConfig(level=logging.INFO)
logging.warn('Warning level message')
所有日志级别都显示在 GAE 中的任何日志级别下,与严重性级别无关。
我尝试使用Python 的 Stackdriver 日志记录客户端:
import logging
from google.cloud import logging as gcloud_logging
client = gcloud_logging.Client()
client.setup_logging(logging.INFO)
logging.basicConfig(level=logging.INFO)
logging.warn('Warning level message')
在本地执行时,此日志会记录到 Stackdriver(在“全局”下),日志级别实际上运行正常。但是,当我在 GAE 中部署此应用程序时,GAE 的日志级别仍显示在“任何日志级别”下。此外,“全局”下的日志记录似乎不起作用。
有没有一种简单的方法可以让日志严重级别与带有 python 3 的谷歌标准应用程序引擎一起工作?
解决方案
您是否尝试过将 Stackdriver Logging 与 Python 日志记录模块集成?
import logging
handler = client.get_default_handler()
cloud_logger = logging.getLogger('cloudLogger')
cloud_logger.setLevel(logging.INFO)
cloud_logger.addHandler(handler)
cloud_logger.error('bad news')
推荐阅读
- angular - formBuilder 控件的 setValue() 和 patchValue() 方法在 cordova 插件的方法调用中不起作用
- unity3d - 在 Unity3d 中切换渲染器的纹理
- vue.js - vuejs 和 vuetify(CRUD 操作)
- r - 将 Sys.time() 转换为字符而不丢失时区?
- java - Python客户端不接收来自Spring websocket服务器的消息
- python - 如何强制 python 可重现?
- c++ - 使用正则表达式在 C++ 中排除子文件夹
- javascript - 传单 JS Cluster Maker 捕获 ids 孩子
- python - Color network graph node lines on click in Bokeh, Python
- r - 用函数创建矩阵