Google Kubernetes Engine Log Handler

Logging handler for Google Container Engine (GKE).

Formats log messages in a JSON format, so that Kubernetes clusters with the fluentd Google Cloud plugin installed can format their log messages so that metadata such as log level is properly captured.

class google.cloud.logging_v2.handlers.container_engine.ContainerEngineHandler(*, name=None, stream=None)

Bases: logging.StreamHandler

Handler to format log messages the format expected by GKE fluent.

This handler is written to format messages for the Google Container Engine (GKE) fluentd plugin, so that metadata such as log level are properly set.

  • Parameters

    • name (Optional[str ]) – The name of the custom log in Cloud Logging.

    • stream (Optional[IO]) – Stream to be used by the handler.

format(record)

Format the message into JSON expected by fluentd.

  • Parameters

    record (logging.LogRecord) – The log record.

  • Returns

    A JSON string formatted for GKE fluentd.

  • Return type

    str

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月30日 UTC.