# Path: google/cloud/logging_v2/handlers/transports/background_thread.py
# class BackgroundThreadTransport(Transport):
#     """Asynchronous transport that uses a background thread."""
# 
#     def __init__(
#         self,
#         client,
#         name,
#         *,
#         grace_period=_DEFAULT_GRACE_PERIOD,
#         batch_size=_DEFAULT_MAX_BATCH_SIZE,
#         max_latency=_DEFAULT_MAX_LATENCY,
#         resource=_GLOBAL_RESOURCE,
#         **kwargs,
#     ):
#         """
#         Args:
#             client (~logging_v2.client.Client):
#                 The Logging client.
#             name (str): The name of the lgoger.
#             grace_period (Optional[float]): The amount of time to wait for pending logs to
#                 be submitted when the process is shutting down.
#             batch_size (Optional[int]): The maximum number of items to send at a time in the
#                 background thread.
#             max_latency (Optional[float]): The amount of time to wait for new logs before
#                 sending a new batch. It is strongly recommended to keep this smaller
#                 than the grace_period. This means this is effectively the longest
#                 amount of time the background thread will hold onto log entries
#                 before sending them to the server.
#             resource (Optional[Resource|dict]): The default monitored resource to associate
#                 with logs when not specified
#         """
#         self.client = client
#         logger = self.client.logger(name, resource=resource)
#         self.worker = _Worker(
#             logger,
#             grace_period=grace_period,
#             max_batch_size=batch_size,
#             max_latency=max_latency,
#         )
#         self.worker.start()
# 
#     def send(self, record, message, **kwargs):
#         """Overrides Transport.send().
# 
#         Args:
#             record (logging.LogRecord): Python log record that the handler was called with.
#             message (str or dict): The message from the ``LogRecord`` after being
#                 formatted by the associated log formatters.
#             kwargs: Additional optional arguments for the logger
#         """
#         self.worker.enqueue(record, message, **kwargs)
# 
#     def flush(self):
#         """Submit any pending log records."""
#         self.worker.flush()
# 
# Path: google/cloud/logging_v2/handlers/_monitored_resources.py
# def detect_resource(project=""):
#     """Return the default monitored resource based on the local environment.
#     If GCP resource not found, defaults to `global`.
# 
#     Args:
#         project (str): The project ID to pass on to the resource (if needed)
#     Returns:
#         google.cloud.logging.Resource: The default resource based on the environment
#     """
#     gke_cluster_name = retrieve_metadata_server(_GKE_CLUSTER_NAME)
#     gce_instance_name = retrieve_metadata_server(_GCE_INSTANCE_ID)
# 
#     if all([env in os.environ for env in _GAE_ENV_VARS]):
#         # App Engine Flex or Standard
#         return _create_app_engine_resource()
#     elif gke_cluster_name is not None:
#         # Kubernetes Engine
#         return _create_kubernetes_resource()
#     elif all([env in os.environ for env in _LEGACY_FUNCTION_ENV_VARS]) or all(
#         [env in os.environ for env in _FUNCTION_ENV_VARS]
#     ):
#         # Cloud Functions
#         return _create_functions_resource()
#     elif all([env in os.environ for env in _CLOUD_RUN_ENV_VARS]):
#         # Cloud Run
#         return _create_cloud_run_resource()
#     elif gce_instance_name is not None:
#         # Compute Engine
#         return _create_compute_resource()
#     else:
#         # use generic global resource
#         return _create_global_resource(project)
# 
# Path: google/cloud/logging_v2/handlers/_helpers.py
# def get_request_data():
#     """Helper to get http_request and trace data from supported web
#     frameworks (currently supported: Flask and Django).
# 
#     Returns:
#         Tuple[Optional[dict], Optional[str], Optional[str], bool]:
#             Data related to the current http request, trace_id, span_id, and trace_sampled
#             for the request. All fields will be None if a http request isn't found.
#     """
#     checkers = (
#         get_request_data_from_django,
#         get_request_data_from_flask,
#     )
# 
#     for checker in checkers:
#         http_request, trace_id, span_id, trace_sampled = checker()
#         if http_request is not None:
#             return http_request, trace_id, span_id, trace_sampled
# 
#     return None, None, None, False


import collections
import json
import logging
from google.cloud.logging_v2.handlers.transports import BackgroundThreadTransport
from google.cloud.logging_v2.handlers._monitored_resources import detect_resource
from google.cloud.logging_v2.handlers._helpers import get_request_data
    route Python standard logging messages directly to the Stackdriver
    Logging API.

    This handler is used when not in GAE or GKE environment.

    This handler supports both an asynchronous and synchronous transport.

    Example:

    .. code-block:: python

        import logging
        import google.cloud.logging
        from google.cloud.logging_v2.handlers import CloudLoggingHandler

        client = google.cloud.logging.Client()
        handler = CloudLoggingHandler(client)

        cloud_logger = logging.getLogger('cloudLogger')
        cloud_logger.setLevel(logging.INFO)
        cloud_logger.addHandler(handler)

        cloud_logger.error('bad news')  # API call
    """

    def __init__(
        self,
        client,
        *,
        name=DEFAULT_LOGGER_NAME,

# Path: google/cloud/logging_v2/handlers/transports/background_thread.py
# class BackgroundThreadTransport(Transport):
#     """Asynchronous transport that uses a background thread."""
# 
#     def __init__(
#         self,
#         client,
#         name,
#         *,
#         grace_period=_DEFAULT_GRACE_PERIOD,
#         batch_size=_DEFAULT_MAX_BATCH_SIZE,
#         max_latency=_DEFAULT_MAX_LATENCY,
#         resource=_GLOBAL_RESOURCE,
#         **kwargs,
#     ):
#         """
#         Args:
#             client (~logging_v2.client.Client):
#                 The Logging client.
#             name (str): The name of the lgoger.
#             grace_period (Optional[float]): The amount of time to wait for pending logs to
#                 be submitted when the process is shutting down.
#             batch_size (Optional[int]): The maximum number of items to send at a time in the
#                 background thread.
#             max_latency (Optional[float]): The amount of time to wait for new logs before
#                 sending a new batch. It is strongly recommended to keep this smaller
#                 than the grace_period. This means this is effectively the longest
#                 amount of time the background thread will hold onto log entries
#                 before sending them to the server.
#             resource (Optional[Resource|dict]): The default monitored resource to associate
#                 with logs when not specified
#         """
#         self.client = client
#         logger = self.client.logger(name, resource=resource)
#         self.worker = _Worker(
#             logger,
#             grace_period=grace_period,
#             max_batch_size=batch_size,
#             max_latency=max_latency,
#         )
#         self.worker.start()
# 
#     def send(self, record, message, **kwargs):
#         """Overrides Transport.send().
# 
#         Args:
#             record (logging.LogRecord): Python log record that the handler was called with.
#             message (str or dict): The message from the ``LogRecord`` after being
#                 formatted by the associated log formatters.
#             kwargs: Additional optional arguments for the logger
#         """
#         self.worker.enqueue(record, message, **kwargs)
# 
#     def flush(self):
#         """Submit any pending log records."""
#         self.worker.flush()
# 
# Path: google/cloud/logging_v2/handlers/_monitored_resources.py
# def detect_resource(project=""):
#     """Return the default monitored resource based on the local environment.
#     If GCP resource not found, defaults to `global`.
# 
#     Args:
#         project (str): The project ID to pass on to the resource (if needed)
#     Returns:
#         google.cloud.logging.Resource: The default resource based on the environment
#     """
#     gke_cluster_name = retrieve_metadata_server(_GKE_CLUSTER_NAME)
#     gce_instance_name = retrieve_metadata_server(_GCE_INSTANCE_ID)
# 
#     if all([env in os.environ for env in _GAE_ENV_VARS]):
#         # App Engine Flex or Standard
#         return _create_app_engine_resource()
#     elif gke_cluster_name is not None:
#         # Kubernetes Engine
#         return _create_kubernetes_resource()
#     elif all([env in os.environ for env in _LEGACY_FUNCTION_ENV_VARS]) or all(
#         [env in os.environ for env in _FUNCTION_ENV_VARS]
#     ):
#         # Cloud Functions
#         return _create_functions_resource()
#     elif all([env in os.environ for env in _CLOUD_RUN_ENV_VARS]):
#         # Cloud Run
#         return _create_cloud_run_resource()
#     elif gce_instance_name is not None:
#         # Compute Engine
#         return _create_compute_resource()
#     else:
#         # use generic global resource
#         return _create_global_resource(project)
# 
# Path: google/cloud/logging_v2/handlers/_helpers.py
# def get_request_data():
#     """Helper to get http_request and trace data from supported web
#     frameworks (currently supported: Flask and Django).
# 
#     Returns:
#         Tuple[Optional[dict], Optional[str], Optional[str], bool]:
#             Data related to the current http request, trace_id, span_id, and trace_sampled
#             for the request. All fields will be None if a http request isn't found.
#     """
#     checkers = (
#         get_request_data_from_django,
#         get_request_data_from_flask,
#     )
# 
#     for checker in checkers:
#         http_request, trace_id, span_id, trace_sampled = checker()
#         if http_request is not None:
#             return http_request, trace_id, span_id, trace_sampled
# 
#     return None, None, None, False


# Path: google/cloud/logging_v2/handlers/handlers.py
import collections
import json
import logging
from google.cloud.logging_v2.handlers.transports import BackgroundThreadTransport
from google.cloud.logging_v2.handlers._monitored_resources import detect_resource
from google.cloud.logging_v2.handlers._helpers import get_request_data

    route Python standard logging messages directly to the Stackdriver
    Logging API.

    This handler is used when not in GAE or GKE environment.

    This handler supports both an asynchronous and synchronous transport.

    Example:

    .. code-block:: python

        import logging
        import google.cloud.logging
        from google.cloud.logging_v2.handlers import CloudLoggingHandler

        client = google.cloud.logging.Client()
        handler = CloudLoggingHandler(client)

        cloud_logger = logging.getLogger('cloudLogger')
        cloud_logger.setLevel(logging.INFO)
        cloud_logger.addHandler(handler)

        cloud_logger.error('bad news')  # API call
    """

    def __init__(
        self,
        client,
        *,
        name=DEFAULT_LOGGER_NAME,

        transport=BackgroundThreadTransport,