o
    id                     @  s   U d 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mZmZmZ ddlZddlmZmZmZmZmZ dd	lmZ eg d
Zded< erQddlmZ G dd deZdddZdS )z5Integration with the standard library logging module.    )annotations)Mapping)NOTSETHandler	LogRecordStreamHandler)TYPE_CHECKINGAnyClassVarcastN   )ATTRIBUTES_LOGGING_ARGS_KEYATTRIBUTES_LOGGING_NAMEATTRIBUTES_MESSAGE_KEYATTRIBUTES_MESSAGE_TEMPLATE_KEYLOGGING_TO_OTEL_LEVEL_NUMBERS)is_instrumentation_suppressed)argsasctimecreatedexc_infoexc_textfilenamefuncName	levelnamelevelnolinenomodulemsecsmessagemsgnamepathnameprocessprocessNamerelativeCreated
stack_infothread
threadNametaskNamezfrozenset[str]RESERVED_ATTRS)Logfirec                      sN   e Zd ZU dZdZded< ee dfd fddZdddZ	dddZ
  ZS )LogfireLoggingHandlera  A [logging](../../integrations/logging.md) handler that sends logs to **Logfire**.

    Args:
        level: The threshold level for this handler. Logging messages which are less severe than *level* will be ignored.
        fallback: A fallback handler to use when [instrumentation is suppressed](../../how-to-guides/suppress.md#suppress-instrumentation).
        logfire_instance: The Logfire instance to use when emitting logs. Defaults to the default global instance.
    zstdlib.loggingzClassVar[str]custom_scope_suffixNlevel	int | strfallbackLoggingHandlerlogfire_instanceLogfire | NonereturnNonec                   s.   t  j|d || _|ptjj| jd| _d S )N)r.   )r-   )super__init__r0   logfireDEFAULT_LOGFIRE_INSTANCEwith_settingsr-   r2   )selfr.   r0   r2   	__class__ b/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/logfire/integrations/logging.pyr7   A   s
   
zLogfireLoggingHandler.__init__recordr   c                 C  sP   t  r| j| dS | |}| jj|t|jt	
|j|j||jd dS )z\Send the log to Logfire.

        Args:
            record: The log record to send.
        N)msg_templater.   
attributesr   )r   r0   handlefill_attributesr2   logpopr   r    r   getr   r   )r;   r@   rB   r>   r>   r?   emitM   s   

zLogfireLoggingHandler.emitdict[str, Any]c                 C  sZ   dd |j  D }|j|d< |j|d< |j|d< |j|t< t|\|t< }|	| |S )zFill the attributes to send to Logfire.

        This method can be overridden to add more attributes.

        Args:
            record: The log record.

        Returns:
            The attributes for the log record.
        c                 S  s   i | ]\}}|t vr||qS r>   )r*   ).0kvr>   r>   r?   
<dictcomp>k   s    z9LogfireLoggingHandler.fill_attributes.<locals>.<dictcomp>zcode.filepathzcode.linenozcode.function)
__dict__itemsr"   r   r   r!   r   _format_messager   update)r;   r@   rB   r   r>   r>   r?   rD   `   s   




z%LogfireLoggingHandler.fill_attributes)r.   r/   r0   r1   r2   r3   r4   r5   )r@   r   r4   r5   )r@   r   r4   rI   )__name__
__module____qualname____doc__r-   __annotations__r   r   r7   rH   rD   __classcell__r>   r>   r<   r?   r,   6   s   
 
r,   r@   r   r4   tuple[str, Mapping[str, Any]]c                 C  sv   | j }| j}|s|i fS t|tu r|| t|ifS z||f }W n ty3   || td|f Y S w |t|fifS )NzMapping[str, Any])r   r    typetupler   	TypeErrorr   )r@   r   r    	formattedr>   r>   r?   rP   w   s   
rP   )r@   r   r4   rX   ) rU   
__future__r   collections.abcr   loggingr   r   r1   r   r   typingr   r	   r
   r   r8   _internal.constantsr   r   r   r   r   _internal.utilsr   	frozensetr*   rV    r+   r,   rP   r>   r>   r>   r?   <module>   s    A