U
    x^%                     @   s   d Z ddlZddlZedZejejkr6e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.

    NZ
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   6/tmp/pip-install-dq5v43_d/SQLAlchemy/sqlalchemy/log.py_add_default_handler!   s
    r   c                    sF   t | jd | j   fdd| _ fdd| _ | _t|  | S )N.c                    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   /   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   s   | j tjS r   )r	   r   r   r   r   r   r   r   r   8   s    zIdentified._should_log_debugc                 C   s   | j tjS r   )r	   r   r   r   r   r   r   r   r   ;   s    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   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__Z   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%   f   s    zInstanceLogger.debugc                 O   s   | j tj|f|| dS )z/Delegate an info call to the underlying logger.N)r+   r   r   r,   r   r   r   infok   s    zInstanceLogger.infoc                 O   s   | j tj|f|| dS )z1Delegate a warning call to the underlying logger.N)r+   r   WARNINGr,   r   r   r   warningp   s    zInstanceLogger.warningc                 O   s   | j tj|f|| dS )zB
        Delegate an error call to the underlying logger.
        Nr+   r   ERRORr,   r   r   r   errorw   s    zInstanceLogger.errorc                 O   s"   d|d< | j tj|f|| dS )z4Delegate an exception call to the underlying logger.   exc_infoNr3   r,   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)r+   r   CRITICALr,   r   r   r   critical   s    zInstanceLogger.criticalc                 O   sR   | j jj|krdS | j| j }|tjkr2| j  }||krN| j j|||f| 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)	r	   managerdisabler'   r&   r   NOTSETgetEffectiveLevel_log)r   levelr-   r.   r/   Zselected_levelr   r   r   r+      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	   r;   r<   r>   r   r@   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   r=   r	   r>   rA   r   r   r   r>      s    

z InstanceLogger.getEffectiveLevelN)r   r   r"   __doc__r   r=   r   r   r'   r*   r%   r0   r2   warnr5   r8   r:   r+   r   r>   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krNt|}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    
rH   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   )rE   )r   rF   ownerr   r   r   __get__   s    zecho_property.__get__c                 C   s   t ||d d S )N)rG   )rH   )r   rF   valuer   r   r   __set__   s    zecho_property.__set__N)r   r   r"   rB   rK   rM   r   r   r   r   rI      s   
rI   )N)rB   r   r   r   Z
rootloggerr@   r=   setLevelWARNr   setr   r    objectr!   r$   rH   rI   r   r   r   r   <module>	   s   
	
o
