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 overridesend()
.- Parameters
- 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
- 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
- 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