【问题标题】:GAE flexible and Stackriver log severity levels with pythonGAE 灵活和 Stackriver 使用 python 记录严重性级别
【发布时间】:2019-03-16 13:29:28
【问题描述】:

我正在谷歌灵活应用引擎中运行 python 3 应用程序。我正在使用默认的 python 根记录器,并希望能够查看 this image 中的日志级别。

使用 gunicorn 在 GAE 中部署具有以下日志配置的应用程序时:

import logging

logging.basicConfig(level=logging.INFO)
logging.warn('Warning level message')

所有日志级别都显示在 GAE 中的 any log level 下,与严重级别无关。

我尝试使用Stackdriver logging client for python:

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 的谷歌标准应用引擎一起工作?

【问题讨论】:

  • 将近 2 年没有 Google 方面的修复...

标签: python python-3.x google-app-engine google-cloud-platform stackdriver


【解决方案1】:

您是否尝试过将 Stackdriver Logging 与 Python 日志记录模块集成?

来自https://gcloud-python.readthedocs.io/en/latest/logging/usage.html#integration-with-python-logging-module:

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')

【讨论】:

  • 在 GAE 中似乎不起作用。仍然显示在任何日志级别下。
  • 我遇到了同样的问题
猜你喜欢
  • 1970-01-01
  • 2019-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-26
  • 2015-06-23
  • 2019-06-06
  • 1970-01-01
相关资源
最近更新 更多