On January 1, 2020 this library will no longer support Python 2 on the latest released version. Previously released library versions will continue to be available. For more information please visit Python 2 support on Google Cloud.

Google App Engine flexible Log Handler

Logging handler for App Engine Flexible

Sends logs to the Stackdriver Logging API with the appropriate resource and labels for App Engine logs.

class google.cloud.logging.handlers.app_engine.AppEngineHandler(client, name='app', transport=<class 'google.cloud.logging.handlers.transports.background_thread.BackgroundThreadTransport'>, stream=None)[source]

Bases: logging.StreamHandler

A logging handler that sends App Engine-formatted logs to Stackdriver.

Parameters
  • client (Client) – The authenticated Google Cloud Logging client for this handler to use.

  • transport (type) – The transport class. It should be a subclass of Transport. If unspecified, BackgroundThreadTransport will be used.

  • stream (file-like object) – (optional) stream to be used by the handler.

Initialize the handler.

If stream is not specified, sys.stderr is used.

emit(record)[source]

Actually log the specified logging record.

Overrides the default emit behavior of StreamHandler.

See https://docs.python.org/2/library/logging.html#handler-objects

Parameters

record (logging.LogRecord) – The record to be logged.

get_gae_labels()[source]

Return the labels for GAE app.

If the trace ID can be detected, it will be included as a label. Currently, no other labels are included.

Return type

dict

Returns

Labels for GAE app.

get_gae_resource()[source]

Return the GAE resource using the environment variables.

Return type

Resource

Returns

Monitored resource for GAE.