o
    Rc                     @   s   d Z ddlZddlZddlmZ ddlmZ er!dZerdndZndZdZed	Z	e	j
ejkr6e	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   0D:\Flask\env\Lib\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                         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    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      | j tjS r   )r   r   r   r   r   r   r   r   r$   J      zIdentified._should_log_debugc                 C   r*   r   )r   r   r   r"   r   r   r   r   r%   M   r+   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   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   r0   namer   r   r   __init__l   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/   x       zInstanceLogger.debugc                 O   r5   )z/Delegate an info call to the underlying logger.N)r6   r   r"   r7   r   r   r   info}   r;   zInstanceLogger.infoc                 O   r5   )z1Delegate a warning call to the underlying logger.N)r6   r   WARNINGr7   r   r   r   warning   r;   zInstanceLogger.warningc                 O   r5   )zB
        Delegate an error call to the underlying logger.
        Nr6   r   ERRORr7   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_infoNr?   r7   r   r   r   	exception   s    zInstanceLogger.exceptionc                 O   r5   )z2Delegate a critical call to the underlying logger.N)r6   r   CRITICALr7   r   r   r   critical   r;   zInstanceLogger.criticalc                 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 )zDelegate 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disabler1   r0   r   NOTSETgetEffectiveLevel
STACKLEVELgetSTACKLEVEL_OFFSET_log)r   levelr8   r9   r:   Zselected_levelr   r   r   r6      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   rG   rH   rJ   r   rO   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?)r1   r0   r   rI   r   rJ   rP   r   r   r   rJ      s   

z InstanceLogger.getEffectiveLevelN)r   r   r,   __doc__r   rI   r"   r   r1   r4   r/   r<   r>   warnrA   rC   rE   r6   r   rJ   r   r   r   r   r.   Q   s$    r.   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___echor   r#   r.   r   )instanceechoflagr3   r   r   r   r   instance_logger   s   


rW   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   )rT   )r   rU   ownerr   r   r   __get__   s   zecho_property.__get__c                 C   s   t ||d d S )N)rV   )rW   )r   rU   valuer   r   r   __set__   s   zecho_property.__set__N)r   r   r,   rQ   rZ   r\   r   r   r   r   rX      s    
rX   r   )rQ   r   r   utilr   r   rK   rM   r#   Z
rootloggerrO   rI   setLevelWARNr   setr&   r   r(   objectr)   r.   rW   rX   r   r   r   r   <module>   s*   
	

t