@@ -162,6 +162,7 @@ def _do_log(self, client, _entry_class, payload=None, **kw):
162
162
163
163
api_repr = entry .to_api_repr ()
164
164
entries = [api_repr ]
165
+
165
166
if google .cloud .logging_v2 ._instrumentation_emitted is False :
166
167
entries = _add_instrumentation (entries , ** kw )
167
168
google .cloud .logging_v2 ._instrumentation_emitted = True
@@ -200,18 +201,38 @@ def log_text(self, text, *, client=None, **kw):
200
201
self ._do_log (client , TextEntry , text , ** kw )
201
202
202
203
def log_struct (self , info , * , client = None , ** kw ):
203
- """Log a dictionary message
204
+ """Logs a dictionary message.
204
205
205
206
See
206
207
https://cloud.google.com/logging/docs/reference/v2/rest/v2/entries/write
207
208
209
+ The message must be able to be serializable to a Protobuf Struct.
210
+ It must be a dictionary of strings to one of the following:
211
+
212
+ - :class:`str`
213
+ - :class:`int`
214
+ - :class:`float`
215
+ - :class:`bool`
216
+ - :class:`list[str|float|int|bool|list|dict|None]`
217
+ - :class:`dict[str, str|float|int|bool|list|dict|None]`
218
+
219
+ For more details on Protobuf structs, see https://protobuf.dev/reference/protobuf/google.protobuf/#value.
220
+ If the provided dictionary cannot be serialized into a Protobuf struct,
221
+ it will not be logged, and a :class:`ValueError` will be raised.
222
+
208
223
Args:
209
- info (dict): the log entry information
224
+ info (dict[str, str|float|int|bool|list|dict|None]):
225
+ the log entry information.
210
226
client (Optional[~logging_v2.client.Client]):
211
227
The client to use. If not passed, falls back to the
212
228
``client`` stored on the current sink.
213
229
kw (Optional[dict]): additional keyword arguments for the entry.
214
230
See :class:`~logging_v2.entries.LogEntry`.
231
+
232
+ Raises:
233
+ ValueError:
234
+ if the dictionary message provided cannot be serialized into a Protobuf
235
+ struct.
215
236
"""
216
237
for field in _STRUCT_EXTRACTABLE_FIELDS :
217
238
# attempt to copy relevant fields from the payload into the LogEntry body
@@ -405,8 +426,22 @@ def log_text(self, text, **kw):
405
426
def log_struct (self , info , ** kw ):
406
427
"""Add a struct entry to be logged during :meth:`commit`.
407
428
429
+ The message must be able to be serializable to a Protobuf Struct.
430
+ It must be a dictionary of strings to one of the following:
431
+
432
+ - :class:`str`
433
+ - :class:`int`
434
+ - :class:`float`
435
+ - :class:`bool`
436
+ - :class:`list[str|float|int|bool|list|dict|None]`
437
+ - :class:`dict[str, str|float|int|bool|list|dict|None]`
438
+
439
+ For more details on Protobuf structs, see https://protobuf.dev/reference/protobuf/google.protobuf/#value.
440
+ If the provided dictionary cannot be serialized into a Protobuf struct,
441
+ it will not be logged, and a :class:`ValueError` will be raised during :meth:`commit`.
442
+
408
443
Args:
409
- info (dict): The struct entry,
444
+ info (dict[str, str|float|int|bool|list|dict|None] ): The struct entry,
410
445
kw (Optional[dict]): Additional keyword arguments for the entry.
411
446
See :class:`~logging_v2.entries.LogEntry`.
412
447
"""
@@ -451,6 +486,10 @@ def commit(self, *, client=None, partial_success=True):
451
486
Whether a batch's valid entries should be written even
452
487
if some other entry failed due to a permanent error such
453
488
as INVALID_ARGUMENT or PERMISSION_DENIED.
489
+
490
+ Raises:
491
+ ValueError:
492
+ if one of the messages in the batch cannot be successfully parsed.
454
493
"""
455
494
if client is None :
456
495
client = self .client
0 commit comments