【发布时间】:2021-05-25 08:02:37
【问题描述】:
我正在尝试使用 Cloud Logging API 云客户端库将日志从 Python 应用程序写入 Logging,其“执行 ID”与谷歌的默认值相同。
记录器设置:
from google.cloud import logging
from google.cloud.logging.resource import Resource
log_client = logging.Client()
# This is the resource type of the log
log_name = 'cloudfunctions.googleapis.com%2Fcloud-functions'
# Inside the resource, nest the required labels specific to the resource type
res = Resource(type="cloud_function",
labels={
"function_name": "my-function",
"region": "asia-east2"
})
logger = log_client.logger(log_name.format("my-project"))
写日志:
logger.log_struct({"message": request.remote_addr}, resource=res, severity='INFO')
【问题讨论】:
标签: python-3.x logging google-cloud-functions