o
    Zhe%                     @   sL  d dl mZ d dlZd dlmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlmZ d dlmZmZ d dlmZ erVd d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ ejZejZejdejdejdejdej dejdej!dej"diZ#e$g dZ%dd Z&G dd deZ'G dd dej(e)Z*G dd de*Z+e+Z,G dd de*Z-dS )    )absolute_importN)fnmatch)Hub)	to_stringevent_from_exceptioncurrent_stacktracecapture_internal_exceptions)Integration)	iteritemsutc_from_timestamp)TYPE_CHECKING)MutableMapping)	LogRecord)Any)Dict)OptionalZnotsetdebuginfowarningerrorfatal)zsentry_sdk.errorszurllib3.connectionpoolzurllib3.connectionc                 C   s   t |  dS )a|  This disables recording (both in breadcrumbs and as events) calls to
    a logger of a specific name.  Among other uses, many of our integrations
    use this to prevent their actions being recorded as breadcrumbs. Exposed
    to users as a way to quiet spammy loggers.

    :param name: The name of the logger to ignore (same string you would pass to ``logging.getLogger``).
    N)_IGNORED_LOGGERSadd)name r   V/var/www/html/lang_env/lib/python3.10/site-packages/sentry_sdk/integrations/logging.pyignore_logger1   s   r   c                   @   s2   e Zd ZdZeefddZdd Zedd Z	dS )	LoggingIntegrationloggingc                 C   s<   d | _ d | _|d urt|d| _|d urt|d| _ d S d S )N)level)_handler_breadcrumb_handlerBreadcrumbHandlerEventHandler)selfr   Zevent_levelr   r   r   __init__B   s   zLoggingIntegration.__init__c                 C   sT   | j d ur|j| j jkr| j | | jd ur&|j| jjkr(| j| d S d S d S N)r    levelnor   handler!   r$   recordr   r   r   _handle_recordM   s   
z!LoggingIntegration._handle_recordc                     s    t jj  fdd} | t j_d S )Nc              	      s   t }z! | |W |d ur!|j|vr"tjt}|d ur#|| S S S S |d ur=|j|vr>tjt}|d ur?|| w w w w r&   )r   r   r   currentZget_integrationr   r+   )r$   r*   Zignored_loggersZintegrationZold_callhandlersr   r   sentry_patched_callhandlers]   s   
zBLoggingIntegration.setup_once.<locals>.sentry_patched_callhandlers)r   LoggercallHandlers)r.   r   r-   r   
setup_onceX   s   zLoggingIntegration.setup_onceN)
__name__
__module____qualname__
identifierDEFAULT_LEVELDEFAULT_EVENT_LEVELr%   r+   staticmethodr1   r   r   r   r   r   ?   s    r   c                   @   s,   e Zd ZedZdd Zdd Zdd ZdS )	_BaseHandler)argscreatedexc_infoexc_textfilenamefuncName	levelnamer'   Zlinennolinenomessagemodulemsecsmsgr   pathnameprocessprocessNamerelativeCreatedstacktagsZtaskNamethread
threadName
stack_infoc                 C   s    t D ]}t|j|r dS qdS )z'Prevents ignored loggers from recordingFT)r   r   r   )r$   r*   loggerr   r   r   _can_record   s
   z_BaseHandler._can_recordc                 C   s    t |j|jr|j S dS )N )LOGGING_TO_EVENT_LEVELgetr'   r@   lowerr)   r   r   r   _logging_to_event_level   s
   z$_BaseHandler._logging_to_event_levelc                    s    fddt t|D S )Nc                    s4   i | ]\}}| j vrt|tr|d s||qS )_)COMMON_RECORD_ATTRS
isinstancestr
startswith).0kvr$   r   r   
<dictcomp>   s    
z3_BaseHandler._extra_from_record.<locals>.<dictcomp>)r
   varsr)   r   r^   r   _extra_from_record   s   

z_BaseHandler._extra_from_recordN)r2   r3   r4   	frozensetrW   rP   rU   ra   r   r   r   r   r9   r   s    r9   c                   @   s    e Zd ZdZdd Zdd ZdS )r#   z
    A logging handler that emits Sentry events for each log record

    Note that you do not have to use this class if the logging integration is enabled, which it is by default.
    c                 C   >   t   | | | |W  d    S 1 sw   Y  d S r&   r   format_emitr)   r   r   r   emit      
$zEventHandler.emitc           	      C   s`  |  |sd S tj}|jd u rd S |jj}|jr-|jd d ur-t|j|dddd\}}n9|jrb|jd d u rbi }i }t  dt|d |d d	d
ddgi|d< W d    n1 s\w   Y  ni }i }||d< | 	|}|dv rw||d< |j
|d< |j
dko|jdk}|r|jd }|dd|d< nt|j|jd|d< | ||d< |j||d d S )Nr   r   T)typeZhandled)client_optionsZ	mechanismvaluesinclude_local_variablesmax_value_length)rl   rm   F)Z
stacktraceZcrashedr,   threads
log_record>   r   r   r   r   r   criticalr   rO   zpy.warningsz%sr   )rB   paramsZlogentryextrahint)rP   r   r,   clientoptionsr<   r   r   r   rU   r   rE   r:   r   ra   Zcapture_event)	r$   r*   Zhubrj   eventrt   r   Z%record_caputured_from_warnings_modulerE   r   r   r   rf      sb   






zEventHandler._emitN)r2   r3   r4   __doc__rg   rf   r   r   r   r   r#      s    r#   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	r"   z
    A logging handler that records breadcrumbs for each log record.

    Note that you do not have to use this class if the logging integration is enabled, which it is by default.
    c                 C   rc   r&   rd   r)   r   r   r   rg     rh   zBreadcrumbHandler.emitc                 C   s,   |  |sd S tjj| |d|id d S )Nro   rs   )rP   r   r,   Zadd_breadcrumb_breadcrumb_from_recordr)   r   r   r   rf     s
   

zBreadcrumbHandler._emitc                 C   s(   d|  ||j|jt|j| |dS )Nlog)ri   r   categoryrB   	timestampdata)rU   r   rB   r   r;   ra   r)   r   r   r   ry     s   z)BreadcrumbHandler._breadcrumb_from_recordN)r2   r3   r4   rx   rg   rf   ry   r   r   r   r   r"     s
    	r"   ).
__future__r   r   r   Zsentry_sdk.hubr   Zsentry_sdk.utilsr   r   r   r   Zsentry_sdk.integrationsr	   Zsentry_sdk._compatr
   r   Zsentry_sdk._typesr   collections.abcr   r   typingr   r   r   INFOr6   ERRORr7   NOTSETDEBUGWARNWARNINGFATALCRITICALrR   setr   r   r   Handlerobjectr9   r#   ZSentryHandlerr"   r   r   r   r   <module>   sD    37[