Class StructuredLogHandler (3.1.1)

StructuredLogHandler(*, labels=None, stream=None, project_id=None)

Handler to format logs into the Cloud Logging structured log format, and write them to standard output

Inheritance

builtins.object > logging.Filterer > logging.Handler > logging.StreamHandler > StructuredLogHandler

Methods

StructuredLogHandler

StructuredLogHandler(*, labels=None, stream=None, project_id=None)
Parameters
NameDescription
labels Optional[dict]

Additional labels to attach to logs.

stream Optional[IO]

Stream to be used by the handler.

project Optional[str]

Project Id associated with the logs.

format

format(record)

Format the message into structured log JSON.

Parameter
NameDescription
record logging.LogRecord

The log record.

Returns
TypeDescription
strA JSON string formatted for GCP structured logging.