Google App Engine flexible Log Handler#

Logging handler for App Engine Flexible

Logs to the well-known file that the fluentd sidecar container on App Engine Flexible is configured to read from and send to Stackdriver Logging.

See the fluentd configuration here:

https://github.com/GoogleCloudPlatform/appengine-sidecars-docker/tree/master/fluentd_logger

class google.cloud.logging.handlers.app_engine.AppEngineHandler[source]#

Bases: logging.handlers.RotatingFileHandler

A handler that writes to the App Engine fluentd Stackdriver log file.

Writes to the file that the fluentd agent on App Engine Flexible is configured to discover logs and send them to Stackdriver Logging. Log entries are wrapped in JSON and with appropriate metadata. The process of converting the user’s formatted logs into a JSON payload for Stackdriver Logging consumption is implemented as part of the handler itself, and not as a formatting step, so as not to interfere with user-defined logging formats.

Construct the handler

Large log entries will get mangled if multiple workers write to the same file simultaneously, so we’ll use the worker’s PID to pick a log filename.

format(record)[source]#

Format the specified record into the expected JSON structure.

Parameters:record (LogRecord) – the log record
Return type:str
Returns:JSON str to be written to the log file