o
    ŠågŸ!  ã                   @  sn  U d Z ddlm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dlm	Z	 ddlm
Z
 d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rXdZerUdndZndZdZeddd�Zedeed f Ze d¡Zejejkr|e ej¡ d1dd„Zeƒ Zde d< d2d"d#„Z!d3d%d&„Z"eej#d'f Z$G d(d„ dƒZ%G d)d'„ d'ƒZ&	d4d5d-d.„Z'G d/d0„ d0ƒZ(dS )6a”  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.Engine`
and :class:`_pool.Pool` objects, corresponds to a logger specific to that
instance only.

é    )ÚannotationsN)ÚAny)ÚOptional)Úoverload)ÚSet)ÚType)ÚTypeVar)ÚUnioné   )Úpy311)Úpy38)ÚLiteralTé   FÚ_ITÚ
Identified)ÚboundÚdebugÚ
sqlalchemyÚloggerúlogging.LoggerÚreturnÚNonec                 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)r   Úhandler© r    úJ/var/www/html/flaskapp/venv/lib/python3.10/site-packages/sqlalchemy/log.pyÚ_add_default_handler:   s
   ÿr"   zSet[Type[Identified]]Ú_logged_classesÚclsúType[Identified]Ústrc                 C  s   t | dd ƒp| jd | j S )NÚ_sqla_logger_namespaceÚ.)ÚgetattrÚ
__module__Ú__name__©r$   r    r    r!   Ú_qual_logger_name_for_clsE   s   þr-   ú	Type[_IT]c                   s>   t  t| ƒ¡‰ ‡ fdd„| _‡ fdd„| _ˆ | _t | ¡ | S )Nc                   ó   ˆ   tj¡S ©N)ÚisEnabledForr   ÚDEBUG©Úself©r   r    r!   Ú<lambda>N   ó    ÿzclass_logger.<locals>.<lambda>c                   r/   r0   )r1   r   ÚINFOr3   r5   r    r!   r6   Q   r7   )r   Ú	getLoggerr-   Ú_should_log_debugÚ_should_log_infor   r#   Úaddr,   r    r5   r!   Úclass_loggerL   s   
r=   ÚInstanceLoggerc                   @  sB   e Zd ZU dZdZded< ded< ded< ddd„Zddd„ZdS )r   r    NzOptional[str]Úlogging_nameÚ_IdentifiedLoggerTyper   Ú_EchoFlagTypeÚ_echor   Úboolc                 C  ó   | j  tj¡S r0   )r   r1   r   r2   r3   r    r    r!   r:   e   ó   zIdentified._should_log_debugc                 C  rD   r0   )r   r1   r   r8   r3   r    r    r!   r;   h   rE   zIdentified._should_log_info)r   rC   )r+   r*   Ú__qualname__Ú	__slots__r?   Ú__annotations__r:   r;   r    r    r    r!   r   \   s   
 
c                   @  sœ   e Zd ZU dZejejejejdœZde	d< dZ
d'd	d
„Zd(dd„Zd(dd„Zd(dd„ZeZd(dd„Zd(dd„Zd(dd„Zd)dd „Zd*d"d#„Zd+d$d%„Zd&S ),r>   a  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
    )NFTr   rA   rB   )Úechor   rI   Únamer&   c                 C  s@   || _ t |¡| _| j| tjkr| jjst| jƒ d S d S d S r0   )rI   r   r9   r   Ú	_echo_mapr8   Úhandlersr"   )r4   rI   rJ   r    r    r!   Ú__init__‹   s
   ÿzInstanceLogger.__init__ÚmsgÚargsr   Úkwargsr   r   c                 O  ó    | j tj|g|¢R i |¤Ž dS )z/Delegate a debug call to the underlying logger.N)Úlogr   r2   ©r4   rN   rO   rP   r    r    r!   r   —   ó    zInstanceLogger.debugc                 O  rQ   )z/Delegate an info call to the underlying logger.N)rR   r   r8   rS   r    r    r!   Úinfoœ   rT   zInstanceLogger.infoc                 O  rQ   )z1Delegate a warning call to the underlying logger.N)rR   r   ÚWARNINGrS   r    r    r!   Úwarning¡   rT   zInstanceLogger.warningc                 O  rQ   )zB
        Delegate an error call to the underlying logger.
        N©rR   r   ÚERRORrS   r    r    r!   Úerror¨   s    zInstanceLogger.errorc                 O  s(   d|d< | j tj|g|¢R i |¤Ž dS )z4Delegate an exception call to the underlying logger.r
   Úexc_infoNrX   rS   r    r    r!   Ú	exception®   s    zInstanceLogger.exceptionc                 O  rQ   )z2Delegate a critical call to the underlying logger.N)rR   r   ÚCRITICALrS   r    r    r!   Úcritical´   rT   zInstanceLogger.criticalÚlevelÚintc                 O  sr   | j jj|kr	dS | j| j }|tjkr| j  ¡ }||kr7tr)| 	dd¡t
 |d< | 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Ú
stacklevelr
   )r   ÚmanagerÚdisablerK   rI   r   ÚNOTSETÚgetEffectiveLevelÚ
STACKLEVELÚgetÚSTACKLEVEL_OFFSETÚ_log)r4   r_   rN   rO   rP   Úselected_levelr    r    r!   rR   ¹   s   

ÿúzInstanceLogger.logrC   c                 C  s   | j jj|kr	dS ||  ¡ kS )z)Is this logger enabled for level 'level'?F)r   rb   rc   re   ©r4   r_   r    r    r!   r1   Ô   s   zInstanceLogger.isEnabledForc                 C  s$   | j | j }|tjkr| j ¡ }|S )z+What's the effective level for this logger?)rK   rI   r   rd   r   re   rk   r    r    r!   re   Û   s   

z InstanceLogger.getEffectiveLevelN)rI   rA   rJ   r&   )rN   r&   rO   r   rP   r   r   r   )
r_   r`   rN   r&   rO   r   rP   r   r   r   )r_   r`   r   rC   )r   r`   )r+   r*   rF   Ú__doc__r   rd   r8   r2   rK   rH   rG   rM   r   rU   rW   ÚwarnrZ   r\   r^   rR   r1   re   r    r    r    r!   r>   l   s(   
 ü








ÚinstanceÚechoflagrA   c                 C  sT   | j rdt| jƒ| j f }nt| jƒ}|| _|dv r t |¡}nt||ƒ}|| _dS )zEcreate a logger for an instance that implements :class:`.Identified`.z%s.%s)FNN)r?   r-   Ú	__class__rB   r   r9   r>   r   )rn   ro   rJ   r   r    r    r!   Úinstance_loggerä   s   þ


rq   c                   @  s@   e Zd ZdZeddd„ƒZeddd„ƒZddd„Zd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``.
    rn   úLiteral[None]Úownerr%   r   c                 C  ó   d S r0   r    ©r4   rn   rt   r    r    r!   Ú__get__  ó   zecho_property.__get__r   rA   c                 C  ru   r0   r    rv   r    r    r!   rw     rx   úOptional[Identified]ú#Union[echo_property, _EchoFlagType]c                 C  s   |d u r| S |j S r0   )rB   rv   r    r    r!   rw     s   Úvaluer   c                 C  s   t ||d� d S )N)ro   )rq   )r4   rn   r{   r    r    r!   Ú__set__  s   zecho_property.__set__N)rn   rs   rt   r%   r   rr   )rn   r   rt   r%   r   rA   )rn   ry   rt   r%   r   rz   )rn   r   r{   rA   r   r   )r+   r*   rF   rl   r   rw   r|   r    r    r    r!   rr     s    

rr   )r   r   r   r   )r$   r%   r   r&   )r$   r.   r   r.   r0   )rn   r   ro   rA   r   r   ))rl   Ú
__future__r   r   r   Útypingr   r   r   r   r   r   r	   Úutilr   r   Úutil.typingr   rf   rh   r   rC   rA   r9   Ú
rootloggerr_   rd   ÚsetLevelÚWARNr"   Úsetr#   rH   r-   r=   ÚLoggerr@   r   r>   rq   rr   r    r    r    r!   Ú<module>   sD   



yÿ