Transports

These classes define how the CloudLoggingHandler transport logs into GCP. More information in the User Guide

Base Transport

Module containing base class for logging transport.

class google.cloud.logging_v2.handlers.transports.base.Transport(client, name, resource=Resource(type='global', labels={}), **kwargs)

Bases: object

Base class for Google Cloud Logging handler transports.

Subclasses of Transport must have constructors that accept a client and name object, and must override send().

  • Parameters

    • client (Client) – The Logging client.

    • name (str) – The name of the lgoger.

    • resource (Optional[Resource|dict]) – The default monitored resource to associate with logs when not specified

flush()

Submit any pending log records.

For blocking/sync transports, this is a no-op.

send(record, message, **kwargs)

Transport send to be implemented by subclasses.

Background Thread Transport

Transport for Python logging handler

Uses a background worker to log to Cloud Logging asynchronously.

class google.cloud.logging_v2.handlers.transports.background_thread.BackgroundThreadTransport(client, name, *, grace_period=5.0, batch_size=10, max_latency=0, resource=Resource(type='global', labels={}), **kwargs)

Bases: google.cloud.logging_v2.handlers.transports.base.Transport

Asynchronous transport that uses a background thread.

  • Parameters

    • client (Client) – The Logging client.

    • name (str) – The name of the lgoger.

    • grace_period (Optional[float]) – The amount of time to wait for pending logs to be submitted when the process is shutting down.

    • batch_size (Optional[int]) – The maximum number of items to send at a time in the background thread.

    • max_latency (Optional[float]) – The amount of time to wait for new logs before sending a new batch. It is strongly recommended to keep this smaller than the grace_period. This means this is effectively the longest amount of time the background thread will hold onto log entries before sending them to the server.

    • resource (Optional[Resource|dict]) – The default monitored resource to associate with logs when not specified

flush()

Submit any pending log records.

send(record, message, **kwargs)

Overrides Transport.send().

Synchronous Transport

Transport for Python logging handler.

Logs directly to the the Cloud Logging API with a synchronous call.

class google.cloud.logging_v2.handlers.transports.sync.SyncTransport(client, name, resource=Resource(type='global', labels={}), **kwargs)

Bases: google.cloud.logging_v2.handlers.transports.base.Transport

Basic sychronous transport.

Uses this library’s Logging client to directly make the API call.

  • Parameters

    • client (Client) – The Logging client.

    • name (str) – The name of the lgoger.

    • resource (Optional[Resource|dict]) – The default monitored resource to associate with logs when not specified

send(record, message, **kwargs)

Overrides transport.send().