
    	]j                         d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 dZ
dZdZd	Zd
ZdZdZ G d dej"                        Zy)zLogging handler for App Engine Flexible

Sends logs to the Cloud Logging API with the appropriate resource
and labels for App Engine logs.
    N)get_request_data_create_app_engine_resource)BackgroundThreadTransportappGCLOUD_PROJECTGOOGLE_CLOUD_PROJECTGAE_SERVICEGAE_VERSIONz!appengine.googleapis.com/trace_idz@AppEngineHandler is deprecated. Use CloudLoggingHandler instead.c                   B     e Zd ZdZeedd fd
Zd Zd Z fdZ	 xZ
S )AppEngineHandlerz~A logging handler that sends App Engine-formatted logs to Stackdriver.

    DEPRECATED:  use CloudLoggingHandler instead.
    N)name	transportstreamc                   t         t        |   |       || _        || _         |||      | _        t        j                  j                  t        t        j                  j                  t        d            | _        t        j                  j                  t        d      | _        t        j                  j                  t        d      | _        | j!                         | _        t%        j&                  t(        t*               y)a  
        Args:
            client (~logging_v2.client.Client): The authenticated
                Google Cloud Logging client for this handler to use.
            name (Optional[str]): Name for the logger.
            transport (Optional[~logging_v2.transports.Transport]):
                The transport class. It should be a subclass
                of :class:`.Transport`. If unspecified,
                :class:`.BackgroundThreadTransport` will be used.
            stream (Optional[IO]): Stream to be used by the handler.

         N)superr   __init__r   clientr   osenvironget_GAE_PROJECT_ENV_FLEX_GAE_PROJECT_ENV_STANDARD
project_id_GAE_SERVICE_ENV	module_id_GAE_VERSION_ENV
version_idget_gae_resourceresourcewarningswarn_DEPRECATION_MSGDeprecationWarning)selfr   r   r   r   	__class__s        U/root/env/lib/python3.12/site-packages/google/cloud/logging_v2/handlers/app_engine.pyr   zAppEngineHandler.__init__1   s    ( 	.v6	"640**..!2::>>2KR#P
 (8"=**..)92>--/&(:;    c                     t               S )zReturn the GAE resource using the environment variables.

        Returns:
            google.cloud.logging_v2.resource.Resource: Monitored resource for GAE.
        r   )r&   s    r(   r    z!AppEngineHandler.get_gae_resourceR   s     +,,r)   c                 >    i }t               \  }}}}|	||t        <   |S )zReturn the labels for GAE app.

        If the trace ID can be detected, it will be included as a label.
        Currently, no other labels are included.

        Returns:
            dict: Labels for GAE app.
        )r   _TRACE_ID_LABEL)r&   
gae_labels_trace_ids       r(   get_gae_labelszAppEngineHandler.get_gae_labelsZ   s0     
,.8Q*2J'r)   c           	         t         t        |   |      }t               \  }}}}|d| j                   d| }t        |d|      }t        |dd      }t        |d|      }t        |d| j                        }	t        |di       }
| j                         }|j                  |
       | j                  j                  |||	||||	       y)
a  Actually log the specified logging record.

        Overrides the default emit behavior of ``StreamHandler``.

        See https://docs.python.org/2/library/logging.html#handler-objects

        Args:
            record (logging.LogRecord): The record to be logged.
        Nz	projects/z/traces/tracespan_idhttp_requestr!   labels)r!   r5   r2   r3   r4   )r   r   formatr   r   getattrr!   r0   updater   send)r&   recordmessageinferred_httpinferred_tracer.   r2   r3   r4   r!   user_labelsr-   r'   s               r(   emitzAppEngineHandler.emitk   s     ($6v>.>.@+~q!%((9.AQRN8&)T2v~}E6:t}}=fh3((*
+&% 	 	
r)   )__name__
__module____qualname____doc___DEFAULT_GAE_LOGGER_NAMEr   r   r    r0   r?   __classcell__)r'   s   @r(   r   r   +   s-     &+<B-" 
  
r)   r   )rC   loggingr   r"   )google.cloud.logging_v2.handlers._helpersr   5google.cloud.logging_v2.handlers._monitored_resourcesr   +google.cloud.logging_v2.handlers.transportsr   rD   r   r   r   r   r,   r$   StreamHandlerr    r)   r(   <module>rL      s`     	  F R  ( 2     5U `
w,, `
r)   