Context manager: collect entries to log via a single API call.
Helper returned byLogger.batch
Parameters
Name
Description
logger
logging_v2.logger.Logger
the logger to which entries will be logged.
client
logging_V2.client.Client
The client to use.
resource
Optional[logging_v2.resource.Resource]
Monitored resource of the batch, defaults to None, which requires that every entry should have a resource specified. Since the methods used to write entries default the entry's resource to the global resource type, this parameter is only required if explicitly set to None. If no entries' resource are set to None, this parameter will be ignored on the server.
Methods
commit
commit(*,client=None,partial_success=True)
Send saved log entries as a single API call.
Parameters
Name
Description
client
Optional[logging_v2.client.Client]
The client to use. If not passed, falls back to theclientstored on the current batch.
partial_success
Optional[bool]
Whether a batch's valid entries should be written even if some other entry failed due to a permanent error such as INVALID_ARGUMENT or PERMISSION_DENIED.
Exceptions
Type
Description
ValueError
if one of the messages in the batch cannot be successfully parsed.
log
log(message=None,**kw)
Add an arbitrary message to be logged duringcommit.
Type will be inferred based on the input message.
Parameters
Name
Description
kw
Optional[dict]
Additional keyword arguments for the entry. Seelogging_v2.entries.LogEntry.
message
Optional[str or dict or google.protobuf.Message]
The message. to log
log_empty
log_empty(**kw)
Add a entry without payload to be logged duringcommit.
Parameter
Name
Description
kw
Optional[dict]
Additional keyword arguments for the entry. Seelogging_v2.entries.LogEntry.
log_proto
log_proto(message,**kw)
Add a protobuf entry to be logged duringcommit.
Parameters
Name
Description
message
google.protobuf.Message
The protobuf entry.
kw
Optional[dict]
Additional keyword arguments for the entry. Seelogging_v2.entries.LogEntry.
log_struct
log_struct(info,**kw)
Add a struct entry to be logged duringcommit.
The message must be able to be serializable to a Protobuf Struct.
It must be a dictionary of strings to one of the following:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Class Batch (3.12.1)\n\nVersion latestkeyboard_arrow_down\n\n- [3.12.1 (latest)](/python/docs/reference/logging/latest/google.cloud.logging_v2.logger.Batch)\n- [3.12.0](/python/docs/reference/logging/3.12.0/google.cloud.logging_v2.logger.Batch)\n- [3.11.3](/python/docs/reference/logging/3.11.3/google.cloud.logging_v2.logger.Batch)\n- [3.10.0](/python/docs/reference/logging/3.10.0/google.cloud.logging_v2.logger.Batch)\n- [3.9.0](/python/docs/reference/logging/3.9.0/google.cloud.logging_v2.logger.Batch)\n- [3.8.0](/python/docs/reference/logging/3.8.0/google.cloud.logging_v2.logger.Batch)\n- [3.7.0](/python/docs/reference/logging/3.7.0/google.cloud.logging_v2.logger.Batch)\n- [3.6.0](/python/docs/reference/logging/3.6.0/google.cloud.logging_v2.logger.Batch)\n- [3.5.0](/python/docs/reference/logging/3.5.0/google.cloud.logging_v2.logger.Batch)\n- [3.4.0](/python/docs/reference/logging/3.4.0/google.cloud.logging_v2.logger.Batch)\n- [3.3.1](/python/docs/reference/logging/3.3.1/google.cloud.logging_v2.logger.Batch)\n- [3.2.5](/python/docs/reference/logging/3.2.5/google.cloud.logging_v2.logger.Batch)\n- [3.1.2](/python/docs/reference/logging/3.1.2/google.cloud.logging_v2.logger.Batch)\n- [3.0.0](/python/docs/reference/logging/3.0.0/google.cloud.logging_v2.logger.Batch)\n- [2.7.2](/python/docs/reference/logging/2.7.2/google.cloud.logging_v2.logger.Batch)\n- [2.6.0](/python/docs/reference/logging/2.6.0/google.cloud.logging_v2.logger.Batch)\n- [2.5.0](/python/docs/reference/logging/2.5.0/google.cloud.logging_v2.logger.Batch)\n- [2.4.0](/python/docs/reference/logging/2.4.0/google.cloud.logging_v2.logger.Batch)\n- [2.3.1](/python/docs/reference/logging/2.3.1/google.cloud.logging_v2.logger.Batch)\n- [2.2.0](/python/docs/reference/logging/2.2.0/google.cloud.logging_v2.logger.Batch)\n- [2.1.1](/python/docs/reference/logging/2.1.1/google.cloud.logging_v2.logger.Batch)\n- [2.0.2](/python/docs/reference/logging/2.0.2/google.cloud.logging_v2.logger.Batch)\n- [1.15.3](/python/docs/reference/logging/1.15.3/google.cloud.logging_v2.logger.Batch)\n- [1.14.0](/python/docs/reference/logging/1.14.0/google.cloud.logging_v2.logger.Batch)\n- [1.13.0](/python/docs/reference/logging/1.13.0/google.cloud.logging_v2.logger.Batch)\n- [1.12.1](/python/docs/reference/logging/1.12.1/google.cloud.logging_v2.logger.Batch) \n\n Batch(logger, client, *, resource=None)\n\nContext manager: collect entries to log via a single API call.\n\nHelper returned by `Logger.batch`\n\nMethods\n-------\n\n### commit\n\n commit(*, client=None, partial_success=True)\n\nSend saved log entries as a single API call.\n\n### log\n\n log(message=None, **kw)\n\nAdd an arbitrary message to be logged during `commit`.\nType will be inferred based on the input message.\n\n### log_empty\n\n log_empty(**kw)\n\nAdd a entry without payload to be logged during `commit`.\n\n### log_proto\n\n log_proto(message, **kw)\n\nAdd a protobuf entry to be logged during `commit`.\n\n### log_struct\n\n log_struct(info, **kw)\n\nAdd a struct entry to be logged during `commit`.\n\nThe message must be able to be serializable to a Protobuf Struct.\nIt must be a dictionary of strings to one of the following: \n\n - `str`\n - `int`\n - `float`\n - `bool`\n - :class:`list[str|float|int|bool|list|dict|None]`\n - :class:`dict[str, str|float|int|bool|list|dict|None]`\n\nFor more details on Protobuf structs, see \u003chttps://protobuf.dev/reference/protobuf/google.protobuf/#value\u003e.\nIf the provided dictionary cannot be serialized into a Protobuf struct,\nit will not be logged, and a `ValueError` will be raised during `commit`.\n\n### log_text\n\n log_text(text, **kw)\n\nAdd a text entry to be logged during `commit`."]]