As of January 1, 2020 this library no longer supports Python 2 on the latest released version. Library versions released prior to that date will continue to be available. For more information please visit Python 2 support on Google Cloud.

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)[source]

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()[source]

Submit any pending log records.

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

send(record, message, **kwargs)[source]

Transport send to be implemented by subclasses.

Parameters
  • record (logging.LogRecord) – Python log record that the handler was called with.

  • message (str or dict) – The message from the LogRecord after being formatted by the associated log formatters.

  • kwargs – Additional optional arguments for the logger

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)[source]

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()[source]

Submit any pending log records.

send(record, message, **kwargs)[source]

Overrides Transport.send().

Parameters
  • record (logging.LogRecord) – Python log record that the handler was called with.

  • message (str or dict) – The message from the LogRecord after being formatted by the associated log formatters.

  • kwargs – Additional optional arguments for the logger

Synchronous Transport

Transport for Python logging handler.

Logs directly to 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)[source]

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)[source]

Overrides transport.send().

Parameters
  • record (logging.LogRecord) – Python log record that the handler was called with.

  • message (str or dict) – The message from the LogRecord after being formatted by the associated log formatters.

  • kwargs – Additional optional arguments for the logger