【问题标题】:Problem with Google Cloud Live Logging with Python使用 Python 进行 Google Cloud Live Logging 的问题
【发布时间】:2020-04-04 23:58:03
【问题描述】:


我想在我正在工作的项目中实时记录一些日志,搜索后我找到了 Google Cloud Live Logging Api。
在搜索并阅读了不同的指南后,我创建了一个项目并启用了日志记录 API。
然后我尝试使用以下代码对其进行测试。

# Imports the Google Cloud client library
import google.cloud.logging
from google.cloud import logging
from google.oauth2 import service_account

# Imports Python standard library logging
import logging

# Instantiates a client
credentials = service_account.Credentials.from_service_account_file('my_path_to_service_account_json')
client = google.cloud.logging.Client(project='name_of_my_project', credentials=credentials)

# Connects the logger to the root logging handler; by default this captures
# all logs at INFO level and higher
client.setup_logging()


# The data to log
text = 'Hello, world!'

# Emits the data using the standard logging module
logging.warning(text)


它执行成功,我进入谷歌云中的日志查看器检查日志。
那里什么都没有,尽管它在 API 概述中显示了请求。
您对出了什么问题有任何想法吗?是上面的代码 sn-p 中的某些内容,还是我在 Google 云配置部分中遗漏了某些内容?
提前致谢。

【问题讨论】:

    标签: python-3.x logging google-cloud-platform google-api


    【解决方案1】:

    我终于设法解决了这个问题。
    问题不在于代码,而在于我没有在“日志查看器”中选择“全局”。
    当我选择“全球”时,我看到了我所有的日志。

    【讨论】:

      猜你喜欢
      • 2017-08-17
      • 1970-01-01
      • 1970-01-01
      • 2016-03-11
      • 2021-09-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-27
      • 2021-10-08
      相关资源
      最近更新 更多