3
üZð]²  ã               @   s‚   d Z 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dd„ ƒZ
d	d
„ Zeje
ƒZejejdƒƒ dd„ Zdd„ ZdS )zN
flask.logging
~~~~~~~~~~~~~

:copyright: 2010 Pallets
:license: BSD-3-Clause
é    )Úabsolute_importN)Ú
LocalProxyé   )Úrequestc               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	   ú./tmp/pip-build-w1as9q70/flask/flask/logging.pyÚwsgi_errors_stream   s    
r   c                sD   | j ƒ ‰ | }x2|r>t‡ fdd„|jD ƒƒr.dS |js6P |j}qW dS )zšCheck 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Úhandler)r   r	   r
   ú	<genexpr>)   s    z$has_level_handler.<locals>.<genexpr>TF)ÚgetEffectiveLevelÚanyÚhandlersÚ	propagateÚparent)ÚloggerÚcurrentr	   )r   r
   Úhas_level_handler!   s    
r   z6[%(asctime)s] %(levelname)s in %(module)s: %(message)sc             C   s    | j tjkp| jp| jp| j S )zªDecide if a logger has direct configuration applied by checking
    its properties against the defaults.

    :param logger: The :class:`~logging.Logger` to inspect.
    )r   ÚloggingÚNOTSETr   Úfiltersr   )r   r	   r	   r
   Ú_has_config<   s    r   c             C   s~   t j| jƒ}x@dD ]8}t j|ƒ}t|ƒrt|ƒ rtjdj| j|d�ƒ P qW | jrh|j rh|j	t j
ƒ t|ƒsz|jtƒ |S )a½  Get the the Flask apps'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.
    ú	flask.appÚflaskz¸'app.logger' is named '{name}' for this application, but configuration was found for '{old_name}', which no longer has an effect. The logging configuration should be moved to '{name}'.)ÚnameÚold_name)r   r   )r   Ú	getLoggerr   r   ÚwarningsÚwarnÚformatÚdebugr   ÚsetLevelÚDEBUGr   Ú
addHandlerÚdefault_handler)Zappr   r   Z
old_loggerr	   r	   r
   Úcreate_loggerJ   s    


r)   )Ú__doc__Ú
__future__r   r   r   r!   Zwerkzeug.localr   Úglobalsr   r   r   ÚStreamHandlerr(   ÚsetFormatterÚ	Formatterr   r)   r	   r	   r	   r
   Ú<module>   s   
