U
    cme	                     @  s   d dl mZ d dlZd dlZd dlZd dlmZ ddlm	Z	 ej
rNddlmZ eddd	d
ZdddddZeeZeed dddddZdS )    )annotationsN)
LocalProxy   )request)Appzt.TextIO)returnc                   C  s   t rt jd S tjS )a  Find the most appropriate error stream for the application. If a request
    is active, log to ``wsgi.errors``, otherwise use ``sys.stderr``.

    If you configure your own :class:`logging.StreamHandler`, you may want to
    use this for the stream. If you are using file or dict configuration and
    can't import this directly, you can refer to it as
    ``ext://flask.logging.wsgi_errors_stream``.
    zwsgi.errors)r   environsysstderr r   r   1/tmp/pip-unpacked-wheel-n675y88a/flask/logging.pywsgi_errors_stream   s    
r   zlogging.Loggerbool)loggerr   c                   s@   |    | }|r<t fdd|jD r,dS |js4q<|j}qdS )zCheck if there is a handler in the logging chain that will handle the
    given logger's :meth:`effective level <~logging.Logger.getEffectiveLevel>`.
    c                 3  s   | ]}|j  kV  qd S )Nlevel).0handlerr   r   r   	<genexpr>$   s     z$has_level_handler.<locals>.<genexpr>TF)getEffectiveLevelanyhandlers	propagateparent)r   currentr   r   r   has_level_handler   s    r   z6[%(asctime)s] %(levelname)s in %(module)s: %(message)sr   )appr   c                 C  s:   t | j}| jr$|js$|t j t|s6|t	 |S )a  Get the Flask app's logger and configure it if needed.

    The logger name will be the same as
    :attr:`app.import_name <flask.Flask.name>`.

    When :attr:`~flask.Flask.debug` is enabled, set the logger level to
    :data:`logging.DEBUG` if it is not set.

    If there is no handler for the logger's effective level, add a
    :class:`~logging.StreamHandler` for
    :func:`~flask.logging.wsgi_errors_stream` with a basic format.
    )
logging	getLoggernamedebugr   setLevelDEBUGr   
addHandlerdefault_handler)r   r   r   r   r   create_logger7   s    
r%   )
__future__r   r   r	   typingtZwerkzeug.localr   globalsr   TYPE_CHECKINGZ
sansio.appr   r   r   StreamHandlerr$   setFormatter	Formatterr%   r   r   r   r   <module>   s   
