Reputation: 41
I'm trying to retrieve BigQuery audit logs using Stackdriver Logging Client Libraries in Python.
According to the tutorial, the following code should be able to fetch log entries:
for entry in client.list_entries():
do_something_with(entry)
However, this iterator just returns ProtobufEntry
and I couldn't find how to get the actual log message from this object.
for entry in client.list_entries():
print type(entry)
The above code produces the following output:
$ python log_test.py
<class 'google.cloud.logging.entries.ProtobufEntry'>
<class 'google.cloud.logging.entries.ProtobufEntry'>
<class 'google.cloud.logging.entries.ProtobufEntry'>
....
However, I couldn't find any way to parse those objects.
How can I parse actual log messages?
Upvotes: 1
Views: 1564
Reputation: 7058
The fields of a ProtobufEntry
are listed here. If the payload is None
use payload_pb
instead as I found in the code.
The following snippet worked for me:
from google.cloud import logging
client = logging.Client()
for entry in client.list_entries():
timestamp = entry.timestamp.isoformat()
print('* {}: {}'.format
(timestamp, entry.payload_pb))
Upvotes: 2