【发布时间】: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