airflow.providers.google.cloud.log.stackdriver_task_handler
¶
Handler that integrates with Stackdriver
Module Contents¶
Classes¶
Handler that directly makes Stackdriver logging API calls. |
Attributes¶
- class airflow.providers.google.cloud.log.stackdriver_task_handler.StackdriverTaskHandler(gcp_key_path=None, scopes=_DEFAULT_SCOPESS, name=DEFAULT_LOGGER_NAME, transport=BackgroundThreadTransport, resource=_GLOBAL_RESOURCE, labels=None)[source]¶
Bases:
logging.Handler
Handler that directly makes Stackdriver 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.It can also be used to save logs for executing tasks. To do this, you should set as a handler with the name “tasks”. In this case, it will also be used to read the log for display in Web UI.
This handler supports both an asynchronous and synchronous transport.
- Parameters
gcp_key_path (str | None) – Path to Google Cloud Credential JSON file. If omitted, authorization based on the Application Default Credentials will be used.
scopes (Collection[str] | None) – OAuth scopes for the credentials,
name (str) – the name of the custom log in Stackdriver Logging. Defaults to ‘airflow’. The name of the Python logger will be represented in the
python_logger
field.transport (type[google.cloud.logging.handlers.transports.Transport]) – Class for creating new transport objects. It should extend from the base
google.cloud.logging.handlers.Transport
type and implement :meth`google.cloud.logging.handlers.Transport.send`. Defaults togoogle.cloud.logging.handlers.BackgroundThreadTransport
. The other option isgoogle.cloud.logging.handlers.SyncTransport
.resource (google.cloud.logging.Resource) – (Optional) Monitored resource of the entry, defaults to the global resource type.
labels (dict[str, str] | None) – (Optional) Mapping of labels for the entry.
- emit(record)[source]¶
Actually log the specified logging record.
- Parameters
record (logging.LogRecord) – The record to be logged.
- set_context(task_instance)[source]¶
Configures the logger to add information with information about the current task
- Parameters
task_instance (airflow.models.TaskInstance) – Currently executed task
- read(task_instance, try_number=None, metadata=None)[source]¶
Read logs of given task instance from Stackdriver logging.
- Parameters
- Returns
a tuple of ( list of (one element tuple with two element tuple - hostname and logs) and list of metadata)
- Return type