Skip to content

Commit 7d9bce0

Browse files
committed
Convert batch timestamp to string.
1 parent 9ed79fc commit 7d9bce0

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

logging/google/cloud/logging/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def commit(self, client=None):
476476
if http_req is not None:
477477
info['httpRequest'] = http_req
478478
if timestamp is not None:
479-
info['timestamp'] = timestamp
479+
info['timestamp'] = _datetime_to_rfc3339(timestamp)
480480
entries.append(info)
481481

482482
client.logging_api.write_entries(entries, **kwargs)

logging/unit_tests/test_logger.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,10 +667,13 @@ def test_commit_w_bound_client(self):
667667
'type': 'global',
668668
}
669669
ENTRIES = [
670-
{'textPayload': TEXT, 'insertId': IID1, 'timestamp': TIMESTAMP1},
671-
{'jsonPayload': STRUCT, 'insertId': IID2, 'timestamp': TIMESTAMP2},
670+
{'textPayload': TEXT, 'insertId': IID1,
671+
'timestamp': TIMESTAMP1.strftime("%Y-%m-%dT%H:%M:%S.%fZ")},
672+
{'jsonPayload': STRUCT, 'insertId': IID2,
673+
'timestamp': TIMESTAMP2.strftime("%Y-%m-%dT%H:%M:%S.%fZ")},
672674
{'protoPayload': json.loads(MessageToJson(message)),
673-
'insertId': IID3, 'timestamp': TIMESTAMP3},
675+
'insertId': IID3,
676+
'timestamp': TIMESTAMP3.strftime("%Y-%m-%dT%H:%M:%S.%fZ")},
674677
]
675678
client = _Client(project=self.PROJECT)
676679
api = client.logging_api = _DummyLoggingAPI()

0 commit comments

Comments
 (0)