Skip to content

Commit 7ac9c0a

Browse files
author
francois kawala
committed
Changed timestamp type from 'str' to 'datetime.datetime'. Convert the timestamp to a RFC3339 string representation in the helper function _make_entry_resource.
1 parent f52288a commit 7ac9c0a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

logging/google/cloud/logging/logger.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import json
1818

1919
from google.protobuf.json_format import MessageToJson
20+
from google.cloud._helpers import _datetime_to_rfc3339
2021

2122

2223
class Logger(object):
@@ -120,7 +121,8 @@ def _make_entry_resource(self, text=None, info=None, message=None,
120121
:type http_request: dict
121122
:param http_request: (optional) info about HTTP request associated with
122123
the entry
123-
:type timestamp: str
124+
125+
:type timestamp: :class:`datetime.datetime`
124126
:param timestamp: (optional) timestamp of event being logged.
125127
126128
:rtype: dict
@@ -158,7 +160,7 @@ def _make_entry_resource(self, text=None, info=None, message=None,
158160
resource['httpRequest'] = http_request
159161

160162
if timestamp is not None:
161-
resource['timestamp'] = timestamp
163+
resource['timestamp'] = _datetime_to_rfc3339(timestamp)
162164

163165
return resource
164166

@@ -190,7 +192,7 @@ def log_text(self, text, client=None, labels=None, insert_id=None,
190192
:param http_request: (optional) info about HTTP request associated with
191193
the entry
192194
193-
:type timestamp: str
195+
:type timestamp: :class:`datetime.datetime`
194196
:param timestamp: (optional) timestamp of event being logged.
195197
"""
196198
client = self._require_client(client)
@@ -227,7 +229,7 @@ def log_struct(self, info, client=None, labels=None, insert_id=None,
227229
:param http_request: (optional) info about HTTP request associated with
228230
the entry.
229231
230-
:type timestamp: str
232+
:type timestamp: :class:`datetime.datetime`
231233
:param timestamp: (optional) timestamp of event being logged.
232234
"""
233235
client = self._require_client(client)
@@ -264,7 +266,7 @@ def log_proto(self, message, client=None, labels=None, insert_id=None,
264266
:param http_request: (optional) info about HTTP request associated with
265267
the entry.
266268
267-
:type timestamp: str
269+
:type timestamp: :class:`datetime.datetime`
268270
:param timestamp: (optional) timestamp of event being logged.
269271
"""
270272
client = self._require_client(client)
@@ -373,7 +375,7 @@ def log_text(self, text, labels=None, insert_id=None, severity=None,
373375
:param http_request: (optional) info about HTTP request associated with
374376
the entry.
375377
376-
:type timestamp: str
378+
:type timestamp: :class:`datetime.datetime`
377379
:param timestamp: (optional) timestamp of event being logged.
378380
"""
379381
self.entries.append(
@@ -399,7 +401,7 @@ def log_struct(self, info, labels=None, insert_id=None, severity=None,
399401
:param http_request: (optional) info about HTTP request associated with
400402
the entry.
401403
402-
:type timestamp: str
404+
:type timestamp: :class:`datetime.datetime`
403405
:param timestamp: (optional) timestamp of event being logged.
404406
"""
405407
self.entries.append(
@@ -425,7 +427,7 @@ def log_proto(self, message, labels=None, insert_id=None, severity=None,
425427
:param http_request: (optional) info about HTTP request associated with
426428
the entry.
427429
428-
:type timestamp: str
430+
:type timestamp: :class:`datetime.datetime`
429431
:param timestamp: (optional) timestamp of event being logged.
430432
"""
431433
self.entries.append(

0 commit comments

Comments
 (0)