【发布时间】:2019-12-12 16:13:52
【问题描述】:
我正在构建一个工具来下载 GCP 日志,将日志作为单行 json 条目保存到磁盘,然后针对这些日志执行处理。该程序需要同时支持导出到云存储的日志和当前在 stackdriver 中的日志(以部分支持尚未预先配置导出到云存储的环境)。云存储部分已完成,但我无法从 stackdriver 下载日志。
我想在 Python 中实现与 gcloud 函数“gcloud logging read”类似的功能。是的,我可以使用gcloud,但是我想将所有内容都集成到一个工具中。
我目前有这个示例代码来打印命中结果,但是我无法获得 JSON 格式的完整日志条目:
def downloadStackdriver():
client = logging.Client()
FILTER = "resource.type=project"
for entry in client.list_entries(filter_=FILTER):
a = (entry.payload.value)
print(a)
如何像使用 gcloud logging read 一样获得匹配日志的完整 JSON 输出?
基于其他 stackoverflow 页面,我尝试使用 MessageToDict 和 MessageToJson,但收到错误消息
"AttributeError: 'ProtobufEntry' object has no attribute 'DESCRIPTOR'"
【问题讨论】:
标签: python-3.x google-cloud-platform gcloud stackdriver google-cloud-stackdriver