o
    y¬´\%  ã                   @   sŠ   d Z ddlZddlZe d¡Zejejkre ej¡ dd„ Z	e
ƒ Zdd„ ZG dd	„ d	eƒZG d
d„ deƒZddd„ZG dd„ deƒZdS )aˆ  Logging control and utilities.

Control of logging for SA can be performed from the regular python logging
module.  The regular dotted module namespace is used, starting at
'sqlalchemy'.  For class-level logging, the class name is appended.

The "echo" keyword parameter, available on SQLA :class:`.Engine`
and :class:`.Pool` objects, corresponds to a logger specific to that
instance only.

é    NÚ
sqlalchemyc                 C   s*   t  tj¡}| t  d¡¡ |  |¡ d S )Nz.%(asctime)s %(levelname)s %(name)s %(message)s)ÚloggingÚStreamHandlerÚsysÚstdoutÚsetFormatterÚ	FormatterÚ
addHandler)ÚloggerÚhandler© r   ú@/var/www/html/env/lib/python3.10/site-packages/sqlalchemy/log.pyÚ_add_default_handler!   s
   ÿr   c                    sF   t  | jd | j ¡‰ ‡ fdd„| _‡ fdd„| _ˆ | _t | ¡ | S )NÚ.c                    ó   ˆ   tj¡S ©N)ÚisEnabledForr   ÚDEBUG©Úself©r
   r   r   Ú<lambda>.   ó    zclass_logger.<locals>.<lambda>c                    r   r   )r   r   ÚINFOr   r   r   r   r   /   r   )	r   Ú	getLoggerÚ
__module__Ú__name__Ú_should_log_debugÚ_should_log_infor
   Ú_logged_classesÚadd)Úclsr   r   r   Úclass_logger,   s   
r"   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú
IdentifiedNc                 C   ó   | j  tj¡S r   )r
   r   r   r   r   r   r   r   r   8   ó   zIdentified._should_log_debugc                 C   r$   r   )r
   r   r   r   r   r   r   r   r   ;   r%   zIdentified._should_log_info)r   r   Ú__qualname__Úlogging_namer   r   r   r   r   r   r#   5   s    r#   c                   @   sz   e Zd ZdZejejejejdœZdd„ Z	dd„ Z
dd„ Zd	d
„ ZeZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚInstanceLoggera  A logger adapter (wrapper) for :class:`.Identified` subclasses.

    This allows multiple instances (e.g. Engine or Pool instances)
    to share a logger, but have its verbosity controlled on a
    per-instance basis.

    The basic functionality is to return a logging level
    which is based on an instance's echo setting.

    Default implementation is:

    'debug' -> logging.DEBUG
    True    -> logging.INFO
    False   -> Effective level of underlying logger (
    logging.WARNING by default)
    None    -> same as False
    )NFTÚdebugc                 C   s@   || _ t |¡| _| j| tjkr| jjst| jƒ d S d S d S r   )Úechor   r   r
   Ú	_echo_mapr   Úhandlersr   )r   r*   Únamer   r   r   Ú__init__Z   s
   ÿzInstanceLogger.__init__c                 O   ó    | j tj|g|¢R i |¤Ž dS )z/Delegate a debug call to the underlying logger.N)Úlogr   r   ©r   ÚmsgÚargsÚkwargsr   r   r   r)   f   ó    zInstanceLogger.debugc                 O   r/   )z/Delegate an info call to the underlying logger.N)r0   r   r   r1   r   r   r   Úinfok   r5   zInstanceLogger.infoc                 O   r/   )z1Delegate a warning call to the underlying logger.N)r0   r   ÚWARNINGr1   r   r   r   Úwarningp   r5   zInstanceLogger.warningc                 O   r/   )zB
        Delegate an error call to the underlying logger.
        N©r0   r   ÚERRORr1   r   r   r   Úerrorw   s    zInstanceLogger.errorc                 O   s(   d|d< | j tj|g|¢R i |¤Ž dS )z4Delegate an exception call to the underlying logger.é   Úexc_infoNr9   r1   r   r   r   Ú	exception}   s    zInstanceLogger.exceptionc                 O   r/   )z2Delegate a critical call to the underlying logger.N)r0   r   ÚCRITICALr1   r   r   r   Úcriticalƒ   r5   zInstanceLogger.criticalc                 O   sZ   | j jj|kr	dS | j| j }|tjkr| j  ¡ }||kr+| j j|||fi |¤Ž dS dS )zÎDelegate a log call to the underlying logger.

        The level here is determined by the echo
        flag as well as that of the underlying logger, and
        logger._log() is called directly.

        N)	r
   ÚmanagerÚdisabler+   r*   r   ÚNOTSETÚgetEffectiveLevelÚ_log)r   Úlevelr2   r3   r4   Úselected_levelr   r   r   r0   ˆ   s   

ÿzInstanceLogger.logc                 C   s   | j jj|kr	dS ||  ¡ kS )z)Is this logger enabled for level 'level'?F)r
   rA   rB   rD   ©r   rF   r   r   r   r   ž   s   zInstanceLogger.isEnabledForc                 C   s$   | j | j }|tjkr| j ¡ }|S )z+What's the effective level for this logger?)r+   r*   r   rC   r
   rD   rH   r   r   r   rD   ¥   s   

z InstanceLogger.getEffectiveLevelN)r   r   r&   Ú__doc__r   rC   r   r   r+   r.   r)   r6   r8   Úwarnr;   r>   r@   r0   r   rD   r   r   r   r   r(   ?   s$    ür(   c                 C   sb   | j rd| jj| jj| j f }n
d| jj| jjf }|| _|dv r't |¡}nt||ƒ}|| _dS )zEcreate a logger for an instance that implements :class:`.Identified`.z%s.%s.%sz%s.%s)FNN)	r'   Ú	__class__r   r   Ú_echor   r   r(   r
   )ÚinstanceÚechoflagr-   r
   r   r   r   Úinstance_logger®   s   ýþ

rO   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Úecho_propertya}      When ``True``, enable log output for this element.

    This has the effect of setting the Python logging level for the namespace
    of this element's class and object reference.  A value of boolean ``True``
    indicates that the loglevel ``logging.INFO`` will be set for the logger,
    whereas the string value ``debug`` will set the loglevel to
    ``logging.DEBUG``.
    c                 C   s   |d u r| S |j S r   )rL   )r   rM   Úownerr   r   r   Ú__get__×   s   zecho_property.__get__c                 C   s   t ||d� d S )N)rN   )rO   )r   rM   Úvaluer   r   r   Ú__set__Ý   s   zecho_property.__set__N)r   r   r&   rI   rR   rT   r   r   r   r   rP   Ì   s    
rP   r   )rI   r   r   r   Ú
rootloggerrF   rC   ÚsetLevelÚWARNr   Úsetr   r"   Úobjectr#   r(   rO   rP   r   r   r   r   Ú<module>   s   
	

o