o
    ©i¹  ã                   @  sÚ   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
Z
ddlmZmZmZ dd	lmZ d
dlmZ ee
jƒjZG dd„ deƒZG dd„ deƒZze ee
jƒj¡jZW dS  eyl   dZedeƒ Y dS w )z<Integration with [Loguru](https://github.com/Delgan/loguru).é    )ÚannotationsN)Ú	LogRecord)ÚPath)ÚAnyé   )ÚATTRIBUTES_LOGGING_ARGS_KEYÚATTRIBUTES_MESSAGE_KEYÚATTRIBUTES_MESSAGE_TEMPLATE_KEY)Úwarn_at_user_stacklevelé   )ÚLogfireLoggingHandlerc                   @  s   e Zd ZdZdS )ÚLoguruInspectionFailedz¥Warning raised when magic introspection of loguru stack frames fails.

    This may happen if the loguru library changes in a way that breaks the introspection.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úa/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/logfire/integrations/loguru.pyr      s    r   c                      s&   e Zd ZdZdZd	‡ fdd„Z‡  ZS )
ÚLogfireHandlerz0A loguru handler that sends logs to **Logfire**.ÚloguruÚrecordr   Úreturnúdict[str, Any]c                   s   t ƒ  |¡}| | di ¡¡ |jrJ ‚tr~t ¡ }|ry|jtu rt|j	}d|v r/|d |t
< ntdtƒ | d¡}t|ttfƒrG|rF||t< ntdtƒ | d¡}t|tƒrlt| d¡ }tƒrl||jv rl||t< 	 |S tdtƒ 	 |S |j}|stdtƒ |S )	zöFill attributes from a log record.

        It filters out the 'extra' attribute and adds it's content to the attributes.

        Args:
            record: The log record.

        Returns:
            The attributes for the log record.
        ÚextraÚmessagez>Failed to extract message template (span name) for loguru log.Úargsz&Failed to extract args for loguru log.Ú
log_recordz2Failed to extract original message for loguru log.z?Failed to find loguru log frame to extract detailed information)ÚsuperÚfill_attributesÚupdateÚpopr   Ú_LOG_METHOD_CODEÚinspectÚcurrentframeÚf_codeÚf_localsr	   r
   r   ÚgetÚ
isinstanceÚtupleÚlistr   ÚdictÚstrÚmsgr   Úf_back)Úselfr   Ú
attributesÚframeÚframe_localsr   Úoriginal_recordr   ©Ú	__class__r   r   r      sN   

ÿ
€

ÿþ
ôÿúß#ÿzLogfireHandler.fill_attributes)r   r   r   r   )r   r   r   r   Úcustom_scope_suffixr   Ú__classcell__r   r   r3   r   r      s    r   zEFailed to find loguru log method code to extract detailed information)r   Ú
__future__r   r"   Úloggingr   Úpathlibr   Útypingr   r   Ú_internal.constantsr   r   r	   Ú_internal.stack_infor
   r   Ú__file__ÚparentÚLOGURU_PATHÚRuntimeWarningr   r   ÚunwrapÚtypeÚloggerÚ_logÚ__code__r!   Ú	Exceptionr   r   r   r   Ú<module>   s*    @
ÿþ