Module logging_v2.handlers (2.0.2)

Python logging handlers for Cloud Logging.

See more code actions.
CloudLoggingHandler(client, *, name='python', transport=<class 'google.cloud.logging_v2.handlers.transports.background_thread.BackgroundThreadTransport'>, resource=Resource(type='global', labels={}), labels=None, stream=None)

Handler that directly makes Cloud Logging API calls.

This is a Python standard logging handler using that can be used to route Python standard logging messages directly to the Stackdriver Logging API.

This handler is used when not in GAE or GKE environment.

This handler supports both an asynchronous and synchronous transport.

Example:

import logging
import google.cloud.logging
from google.cloud.logging_v2.handlers import CloudLoggingHandler

client
= google.cloud.logging.Client()
handler
= CloudLoggingHandler(client)

cloud_logger
= logging.getLogger('cloudLogger')
cloud_logger
.setLevel(logging.INFO)
cloud_logger
.addHandler(handler)

cloud_logger
.error('bad news')  # API call

Modules Functions

setup_logging

setup_logging(
    handler,
    *,
    excluded_loggers=("google.cloud", "google.auth", "google_auth_httplib2"),
    log_level=20
)

Attach a logging handler to the Python root logger

Excludes loggers that this library itself uses to avoid infinite recursion.

Example:

import logging
import google.cloud.logging
from google.cloud.logging_v2.handlers import CloudLoggingHandler

client
= google.cloud.logging.Client()
handler
= CloudLoggingHandler(client)
google
.cloud.logging.handlers.setup_logging(handler)
logging
.getLogger().setLevel(logging.DEBUG)

logging
.error('bad news')  # API call
Parameters
NameDescription
handler logging.handler

the handler to attach to the global handler

excluded_loggers Optional[Tuple[str]]

The loggers to not attach the handler to. This will always include the loggers in the path of the logging client itself.

log_level Optional[int]

Python logging log level. Defaults to :const:logging.INFO.