U
    ÌZjç  ã                   @   sÈ   d Z ddlZddlZddlmZ ddlmZ erBdZer<dndZndZdZe d	¡Z	e	j
ejkrle	 ej¡ d
d„ Zeƒ Zdd„ 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.Engine`
and :class:`_pool.Pool` objects, corresponds to a logger specific to that
instance only.

é    Né   )Úpy311)Úpy38Té   FZ
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   úQ/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/sqlalchemy/log.pyÚ_add_default_handler,   s
    ÿr   c                 C   s   t | dd ƒp| jd | j S )NZ_sqla_logger_namespaceÚ.)ÚgetattrÚ
__module__Ú__name__©Úclsr   r   r   Ú_qual_logger_name_for_cls7   s    þr   c                    s>   t  t| ƒ¡‰ ‡ fdd„| _‡ fdd„| _ˆ | _t | ¡ | S )Nc                    s   ˆ   tj¡S ©N)ÚisEnabledForr   ÚDEBUG©Úself©r   r   r   Ú<lambda>@   ó    zclass_logger.<locals>.<lambda>c                    s   ˆ   tj¡S r   )r   r   ÚINFOr   r   r   r   r   A   r    )r   Ú	getLoggerr   Ú_should_log_debugÚ_should_log_infor   Ú_logged_classesÚaddr   r   r   r   Úclass_logger>   s    
r'   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú
IdentifiedNc                 C   s   | j  tj¡S r   )r   r   r   r   r   r   r   r   r#   J   s    zIdentified._should_log_debugc                 C   s   | j  tj¡S r   )r   r   r   r!   r   r   r   r   r$   M   s    zIdentified._should_log_info)r   r   Ú__qualname__Úlogging_namer#   r$   r   r   r   r   r(   G   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   s8   || _ t |¡| _| j| tjkr4| jjs4t| jƒ d S r   )Úechor   r"   r   Ú	_echo_mapr!   Úhandlersr   )r   r-   Únamer   r   r   Ú__init__l   s    zInstanceLogger.__init__c                 O   s   | j tj|f|ž|Ž dS )z/Delegate a debug call to the underlying logger.N)Úlogr   r   ©r   ÚmsgÚargsÚkwargsr   r   r   r,   x   s    zInstanceLogger.debugc                 O   s   | j tj|f|ž|Ž dS )z/Delegate an info call to the underlying logger.N)r2   r   r!   r3   r   r   r   Úinfo}   s    zInstanceLogger.infoc                 O   s   | j tj|f|ž|Ž dS )z1Delegate a warning call to the underlying logger.N)r2   r   ÚWARNINGr3   r   r   r   Úwarning‚   s    zInstanceLogger.warningc                 O   s   | j tj|f|ž|Ž dS )zB
        Delegate an error call to the underlying logger.
        N©r2   r   ÚERRORr3   r   r   r   Úerror‰   s    zInstanceLogger.errorc                 O   s"   d|d< | j tj|f|ž|Ž dS )z4Delegate an exception call to the underlying logger.r   Úexc_infoNr:   r3   r   r   r   Ú	exception�   s    zInstanceLogger.exceptionc                 O   s   | j tj|f|ž|Ž dS )z2Delegate a critical call to the underlying logger.N)r2   r   ÚCRITICALr3   r   r   r   Úcritical•   s    zInstanceLogger.criticalc                 O   sj   | j jj|krdS | j| j }|tjkr2| j  ¡ }||krftrR| 	dd¡t
 |d< | j j|||f|Ž 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Údisabler.   r-   r   ÚNOTSETÚgetEffectiveLevelÚ
STACKLEVELÚgetÚSTACKLEVEL_OFFSETÚ_log)r   Úlevelr4   r5   r6   Zselected_levelr   r   r   r2   š   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   rB   rC   rE   ©r   rJ   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   rD   r   rE   rK   r   r   r   rE   ¼   s    

z InstanceLogger.getEffectiveLevelN)r   r   r)   Ú__doc__r   rD   r!   r   r.   r1   r,   r7   r9   Úwarnr<   r>   r@   r2   r   rE   r   r   r   r   r+   Q   s"   ür+   c                 C   sT   | j rdt| jƒ| j f }n
t| jƒ}|| _|dkr@t |¡}n
t||ƒ}|| _dS )zEcreate a logger for an instance that implements :class:`.Identified`.z%s.%s)FNN)r*   r   Ú	__class__Ú_echor   r"   r+   r   )ÚinstanceÚechoflagr0   r   r   r   r   Úinstance_loggerÅ   s    þ

rR   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 kr| S |j S d S r   )rO   )r   rP   Úownerr   r   r   Ú__get__ê   s    zecho_property.__get__c                 C   s   t ||d� d S )N)rQ   )rR   )r   rP   Úvaluer   r   r   Ú__set__ð   s    zecho_property.__set__N)r   r   r)   rL   rU   rW   r   r   r   r   rS   ß   s   
rS   )N)rL   r   r   Úutilr   r   rF   rH   r"   Z
rootloggerrJ   rD   ÚsetLevelÚWARNr   Úsetr%   r   r'   Úobjectr(   r+   rR   rS   r   r   r   r   Ú<module>	   s(   
	
t
