我想使用python以精确的JSON格式从谷歌云中获取所有属性的日志 [英] I want to fetch logs from google cloud, with all the attributes, in the exact JSON format using python

查看:235
本文介绍了我想使用python以精确的JSON格式从谷歌云中获取所有属性的日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 用于logging_client.list_entries中的条目(order_by = DESCENDING,filter_ = FILTER,page_size = 1):

timestamp = entry.timestamp.isoformat()
print('**** {}'。format(entry.payload_pb))
print(entry。 payload_pb)
print('* {}:{}:{}'。format(timestamp,entry.logger.name,entry.insert_id))
$ b

但是 payload_pb ,只有两个属性: value type_url
否则我可以只读取一些值,如 timestamp logName insertId



我想获取' protopayload '中的值。请提出一个方法!

解决方案

原始有效载荷的一个序列化的协议缓冲区消息。您需要将其反序列化以读取邮件中的字段。



https://developers.google.com/protocol-buffers/docs/pythontutorial



原始有效载荷是 任何 消息,并且该值的类型由 type_url

指示

https://developers.google.com/protocol-buffers/docs/proto3#any



获得proto消息后,您可以使用 json_format.MessageToJson


I am using Client Library.

for entry in logging_client.list_entries(order_by=DESCENDING, filter_=FILTER, page_size=1):

    timestamp = entry.timestamp.isoformat()
    print('****{}'.format(entry.payload_pb))
    print (entry.payload_pb)
    print('* {}: {}: {}'.format(timestamp, entry.logger.name, entry.insert_id))

But payload_pb, has just two attributes: value and type_url. And otherwise I can fetch just a few values like timestamp, logName, insertId.

I want to fetch the values inside 'protopayload'. Please suggest a way!

解决方案

The value of the proto payload is a serialized protocol buffer message. You'll need to deserialize it to read the fields within the message.

https://developers.google.com/protocol-buffers/docs/pythontutorial

The proto payload is an Any message, and the type of the value is indicated by type_url

https://developers.google.com/protocol-buffers/docs/proto3#any

Once you have the proto message, you can convert it to JSON with json_format.MessageToJson

这篇关于我想使用python以精确的JSON格式从谷歌云中获取所有属性的日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆