# Transports

3.16.0 (latest) 3.15.0 3.13.0 3.12.1 3.11.3 3.10.0 3.9.0 3.8.0 3.7.0 3.6.0 3.5.0 3.4.0 3.3.1 3.2.5 3.1.2 3.0.0 2.7.2 2.6.0 2.5.0 2.4.0 2.3.1 2.2.0 2.1.1 2.0.2 1.15.3 1.14.0 1.13.0 1.12.1 These classes define how the [`CloudLoggingHandler`](https://docs.cloud.google.com/python/docs/reference/logging/latest/handlers-cloud-logging#google.cloud.logging_v2.handlers.handlers.CloudLoggingHandler)
transport logs into GCP.

## 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`](https://docs.python.org/3/library/functions.html#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*](https://docs.cloud.google.com/python/docs/reference/logging/latest/client#google.cloud.logging_v2.client.Client)) -- The Logging client.

  - **name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- The name of the lgoger.

  - **resource** (*Optional* *\[* [*Resource*](https://docs.cloud.google.com/python/docs/reference/logging/latest/resource#google.cloud.logging_v2.resource.Resource)*\|* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- The default monitored resource to associate
    with logs when not specified

#### close()

Closes the transport and cleans up resources used by it.

This call should be followed up by disowning the transport.

#### 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.

- **Parameters**

  - **record** ([*logging.LogRecord*](https://docs.python.org/3/library/logging.html#logging.LogRecord)) -- Python log record that the handler was called with.

  - **message** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)\* or *\[* dict\*\](<https://docs.python.org/3/library/stdtypes.html#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)

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

Asynchronous transport that uses a background thread.

- **Parameters**

  - **client** ([*Client*](https://docs.cloud.google.com/python/docs/reference/logging/latest/client#google.cloud.logging_v2.client.Client)) -- The Logging client.

  - **name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- The name of the lgoger.

  - **grace_period** (*Optional* *\[* [*float*](https://docs.python.org/3/library/functions.html#float)*\]*) -- The amount of time to wait for pending logs to
    be submitted when the process is shutting down.

  - **batch_size** (*Optional* *\[* [*int*](https://docs.python.org/3/library/functions.html#int)*\]*) -- The maximum number of items to send at a time in the
    background thread.

  - **max_latency** (*Optional* *\[* [*float*](https://docs.python.org/3/library/functions.html#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*](https://docs.cloud.google.com/python/docs/reference/logging/latest/resource#google.cloud.logging_v2.resource.Resource)*\|* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- The default monitored resource to associate
    with logs when not specified

#### close()

Closes the worker thread.

#### flush()

Submit any pending log records.

#### send(record, message, \*\*kwargs)

Overrides Transport.send().

- **Parameters**

  - **record** ([*logging.LogRecord*](https://docs.python.org/3/library/logging.html#logging.LogRecord)) -- Python log record that the handler was called with.

  - **message** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)\* or *\[* dict\*\](<https://docs.python.org/3/library/stdtypes.html#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)

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*](https://docs.cloud.google.com/python/docs/reference/logging/latest/client#google.cloud.logging_v2.client.Client)) -- The Logging client.

  - **name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) -- The name of the lgoger.

  - **resource** (*Optional* *\[* [*Resource*](https://docs.cloud.google.com/python/docs/reference/logging/latest/resource#google.cloud.logging_v2.resource.Resource)*\|* [*dict*](https://docs.python.org/3/library/stdtypes.html#dict)*\]*) -- The default monitored resource to associate
    with logs when not specified

#### close()

Closes the transport and cleans up resources used by it.

This call is usually followed up by cleaning up the reference to the transport.

#### send(record, message, \*\*kwargs)

Overrides transport.send().

- **Parameters**

  - **record** ([*logging.LogRecord*](https://docs.python.org/3/library/logging.html#logging.LogRecord)) -- Python log record that the handler was called with.

  - **message** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)\* or *\[* dict\*\](<https://docs.python.org/3/library/stdtypes.html#dict>)) -- The message from the `LogRecord` after being
    formatted by the associated log formatters.

  - **kwargs** -- Additional optional arguments for the logger