Deprecated: Deprecated since version 3.0.0: Use StructuredLogHandler instead.
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)
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [3.12.1 (latest)](/python/docs/reference/logging/latest/handlers-container-engine)\n- [3.12.0](/python/docs/reference/logging/3.12.0/handlers-container-engine)\n- [3.11.3](/python/docs/reference/logging/3.11.3/handlers-container-engine)\n- [3.10.0](/python/docs/reference/logging/3.10.0/handlers-container-engine)\n- [3.9.0](/python/docs/reference/logging/3.9.0/handlers-container-engine)\n- [3.8.0](/python/docs/reference/logging/3.8.0/handlers-container-engine)\n- [3.7.0](/python/docs/reference/logging/3.7.0/handlers-container-engine)\n- [3.6.0](/python/docs/reference/logging/3.6.0/handlers-container-engine)\n- [3.5.0](/python/docs/reference/logging/3.5.0/handlers-container-engine)\n- [3.4.0](/python/docs/reference/logging/3.4.0/handlers-container-engine)\n- [3.3.1](/python/docs/reference/logging/3.3.1/handlers-container-engine)\n- [3.2.5](/python/docs/reference/logging/3.2.5/handlers-container-engine)\n- [3.1.2](/python/docs/reference/logging/3.1.2/handlers-container-engine)\n- [3.0.0](/python/docs/reference/logging/3.0.0/handlers-container-engine)\n- [2.7.2](/python/docs/reference/logging/2.7.2/handlers-container-engine)\n- [2.6.0](/python/docs/reference/logging/2.6.0/handlers-container-engine)\n- [2.5.0](/python/docs/reference/logging/2.5.0/handlers-container-engine)\n- [2.4.0](/python/docs/reference/logging/2.4.0/handlers-container-engine)\n- [2.3.1](/python/docs/reference/logging/2.3.1/handlers-container-engine)\n- [2.2.0](/python/docs/reference/logging/2.2.0/handlers-container-engine)\n- [2.1.1](/python/docs/reference/logging/2.1.1/handlers-container-engine)\n- [2.0.2](/python/docs/reference/logging/2.0.2/handlers-container-engine)\n- [1.15.3](/python/docs/reference/logging/1.15.3/handlers-container-engine)\n- [1.14.0](/python/docs/reference/logging/1.14.0/handlers-container-engine)\n- [1.13.0](/python/docs/reference/logging/1.13.0/handlers-container-engine)\n- [1.12.1](/python/docs/reference/logging/1.12.1/handlers-container-engine) \n\n\\[DEPRECATED\\] Kubernetes Engine Handler\n========================================\n\n**Deprecated:** Deprecated since version 3.0.0: Use `StructuredLogHandler` instead.\n\nLogging handler for Google Container Engine (GKE).\n\nFormats log messages in a JSON format, so that Kubernetes clusters with the\nfluentd Google Cloud plugin installed can format their log messages so that\nmetadata such as log level is properly captured.\n\n### *class* google.cloud.logging_v2.handlers.container_engine.ContainerEngineHandler(\\*, name=None, stream=None)\n\nBases: [`logging.StreamHandler`](https://docs.python.org/3/library/logging.handlers.html#logging.StreamHandler)\n\nHandler to format log messages the format expected by GKE fluent.\n\nThis handler is written to format messages for the Google Container Engine\n(GKE) fluentd plugin, so that metadata such as log level are properly set.\n\nDEPRECATED: use StructuredLogHandler to write formatted logs to standard out instead.\n\n- **Parameters**\n\n - **name** (*Optional* *\\[* [*str*](https://docs.python.org/3/library/stdtypes.html#str)*\\]*) -- The name of the custom log in Cloud Logging.\n\n - **stream** (*Optional* *\\[* *IO* *\\]*) -- Stream to be used by the handler.\n\n#### format(record)\n\nFormat the message into JSON expected by fluentd.\n\n- **Parameters**\n\n **record** ([*logging.LogRecord*](https://docs.python.org/3/library/logging.html#logging.LogRecord)) -- The log record.\n- **Returns**\n\n A JSON string formatted for GKE fluentd.\n- **Return type**\n\n [str](https://docs.python.org/3/library/stdtypes.html#str)"]]