# Path: google/cloud/logging_v2/handlers/_helpers.py
# def format_stackdriver_json(record, message):
#     """Helper to format a LogRecord in in Stackdriver fluentd format.
# 
#     Returns:
#         str: JSON str to be written to the log file.
# 
#     DEPRECATED:  use StructuredLogHandler to write formatted logs to standard out instead.
#     """
#     subsecond, second = math.modf(record.created)
# 
#     payload = {
#         "message": message,
#         "timestamp": {"seconds": int(second), "nanos": int(subsecond * 1e9)},
#         "thread": record.thread,
#         "severity": record.levelname,
#     }
#     warnings.warn(
#         "format_stackdriver_json is deprecated. Use StructuredLogHandler instead.",
#         DeprecationWarning,
#     )
#     return json.dumps(payload, ensure_ascii=False)


import logging.handlers
import warnings
from google.cloud.logging_v2.handlers._helpers import format_stackdriver_json
class ContainerEngineHandler(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.

    DEPRECATED:  use StructuredLogHandler to write formatted logs to standard out instead.
    """

    def __init__(self, *, name=None, stream=None):
        """
        Args:
            name (Optional[str]): The name of the custom log in Cloud Logging.
            stream (Optional[IO]): Stream to be used by the handler.

        """
        super(ContainerEngineHandler, self).__init__(stream=stream)
        self.name = name
        warnings.warn(_DEPRECATION_MSG, DeprecationWarning)

    def format(self, record):
        """Format the message into JSON expected by fluentd.

        Args:
            record (logging.LogRecord): The log record.

        Returns:
            str: A JSON string formatted for GKE fluentd.
        """
        message = super(ContainerEngineHandler, self).format(record)

# Path: google/cloud/logging_v2/handlers/_helpers.py
# def format_stackdriver_json(record, message):
#     """Helper to format a LogRecord in in Stackdriver fluentd format.
# 
#     Returns:
#         str: JSON str to be written to the log file.
# 
#     DEPRECATED:  use StructuredLogHandler to write formatted logs to standard out instead.
#     """
#     subsecond, second = math.modf(record.created)
# 
#     payload = {
#         "message": message,
#         "timestamp": {"seconds": int(second), "nanos": int(subsecond * 1e9)},
#         "thread": record.thread,
#         "severity": record.levelname,
#     }
#     warnings.warn(
#         "format_stackdriver_json is deprecated. Use StructuredLogHandler instead.",
#         DeprecationWarning,
#     )
#     return json.dumps(payload, ensure_ascii=False)


# Path: google/cloud/logging_v2/handlers/container_engine.py
import logging.handlers
import warnings
from google.cloud.logging_v2.handlers._helpers import format_stackdriver_json

class ContainerEngineHandler(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.

    DEPRECATED:  use StructuredLogHandler to write formatted logs to standard out instead.
    """

    def __init__(self, *, name=None, stream=None):
        """
        Args:
            name (Optional[str]): The name of the custom log in Cloud Logging.
            stream (Optional[IO]): Stream to be used by the handler.

        """
        super(ContainerEngineHandler, self).__init__(stream=stream)
        self.name = name
        warnings.warn(_DEPRECATION_MSG, DeprecationWarning)

    def format(self, record):
        """Format the message into JSON expected by fluentd.

        Args:
            record (logging.LogRecord): The log record.

        Returns:
            str: A JSON string formatted for GKE fluentd.
        """
        message = super(ContainerEngineHandler, self).format(record)

        return format_stackdriver_json(record, message)