�
��g�M � � � d dl Z d dlZd dlZd dlmZ d dlmZmZ d dlZd dlm Z ej
Zdddd�Z G d� d ej
� � Zd
� Zdd�Z G d
� de� � Z G d� dej � � Z G d� dej � � Z G d� de� � Zefd�Zefd�Zedk r/d dlZ e j ej ej �� � j � � dS dS )� N��wraps)�Mapping�Callable)�PercentStylez%(levelname)s: %(message)sz%(message)s)�*�INFO�DEBUGc �. � � e Zd ZdZd� fd� Z� fd�Z� xZS )�LevelFormattera� Log formatter with level-specific formatting.
Formatter class which optionally takes a dict of logging levels to
format strings, allowing to customise the log records appearance for
specific levels.
Attributes:
fmt: A dictionary mapping logging levels to format strings.
The ``*`` key identifies the default format string.
datefmt: As per py:class:`logging.Formatter`
style: As per py:class:`logging.Formatter`
>>> import sys
>>> handler = logging.StreamHandler(sys.stdout)
>>> formatter = LevelFormatter(
... fmt={
... '*': '[%(levelname)s] %(message)s',
... 'DEBUG': '%(name)s [%(levelname)s] %(message)s',
... 'INFO': '%(message)s',
... })
>>> handler.setFormatter(formatter)
>>> log = logging.getLogger('test')
>>> log.setLevel(logging.DEBUG)
>>> log.addHandler(handler)
>>> log.debug('this uses a custom format string')
test [DEBUG] this uses a custom format string
>>> log.info('this also uses a custom format string')
this also uses a custom format string
>>> log.warning("this one uses the default format string")
[WARNING] this one uses the default format string
N�%c �� �� |dk rt d� � �|�t }t |t � � r|}i }nMt |t � � r&t |� � }|� dd � � }nt d|z � � �t t | � � �
||� � | j | _ i | _
|� � � D ]#\ }}t j |� � }|| j
|<