CloudLoggingHandler(client, *, name='python', transport=<class 'google.cloud.logging_v2.handlers.transports.background_thread.BackgroundThreadTransport'>, resource=None, 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
Inheritance
builtins.object > logging.Filterer > logging.Handler > logging.StreamHandler > CloudLoggingHandlerMethods
CloudLoggingHandler
CloudLoggingHandler(client, *, name='python', transport=<class 'google.cloud.logging_v2.handlers.transports.background_thread.BackgroundThreadTransport'>, resource=None, labels=None, stream=None)
Name | Description |
client |
`logging_v2.client.Client`
The authenticated Google Cloud Logging client for this handler to use. |
name |
str
the name of the custom log in Cloud Logging. Defaults to 'python'. The name of the Python logger will be represented in the |
transport |
`logging_v2.transports.Transport`
Class for creating new transport objects. It should extend from the base |
resource |
`logging_v2.resource.Resource`
Resource for this Handler. If not given, will be inferred from the environment. |
labels |
Optional[dict]
Additional labels to attach to logs. |
stream |
Optional[IO]
Stream to be used by the handler. |
emit
emit(record)
Actually log the specified logging record.
Overrides the default emit behavior of StreamHandler
.
See https://docs.python.org/2/library/logging.html#handler-objects
Name | Description |
record |
logging.LogRecord
The record to be logged. |