U
    <g                     @   s   d dl Z d dlZd dlmZ d dlmZmZmZ d dlm	Z	 d dl
mZ dddgZG d	d de jZed
dG dd dZejZdeeef dddZeee ef dddZdS )    N)	dataclass)DictOptionalUnion)ConfigurationError)get_and_applyStdLogOutput	LogConfigparse_logging_configc                   @   s   e Zd Ze Ze ZdS )r   N)__name__
__module____qualname__enumautoSTDERRSTDOUT r   r   :/tmp/pip-unpacked-wheel-w101_d3s/pyhanko/config/logging.pyr      s   T)frozenc                   @   sH   e Zd ZU eeef ed< eeef ed< eeeef dddZ	dS )r	   leveloutputreturnc                 C   s>   t | tstd|  }|dkr(tjS |dkr6tjS | S d S )Nz)Log output must be specified as a string.stderrstdout)
isinstancestrr   lowerr   r   r   )specZspec_lr   r   r   parse_output_spec   s    
zLogConfig.parse_output_specN)
r   r   r   r   intr   __annotations__r   staticmethodr   r   r   r   r   r	      s   
r   c                 C   sf   z| | }W n4 t k
r@   |d k	r,| Y S td| dY nX t|ttfsbtdt| |S )NzLogging config for 'z' does not define a log level.z#Log levels must be int or str, not )KeyErrorr   r   r    r   type)Zsettings_dictkeydefault
level_specr   r   r   _retrieve_log_level/   s    

r(   c           	      C   s   t | tstdt| dtd}t| dtjtj	d}d t||i}| 
di }t |ts`td| D ]H\}}t |tstdt|d}t|d	tjtj	d}t||d
||< qh|S )Nz%logging config should be a dictionaryz
root-level)r&   zroot-outputz	by-modulez"logging.by-module should be a dictz+Keys in logging.by-module should be stringsr   r   )r   r   )r   dictr   r(   DEFAULT_ROOT_LOGGER_LEVELr   r	   r   r   r   getitemsr   )	Zlog_config_specZroot_logger_levelZroot_logger_outputZ
log_configZlogging_by_modulemoduleZmodule_logging_settingsr'   Zoutput_specr   r   r   r
   ?   sB    
   


)N)r   loggingdataclassesr   typingr   r   r   Zpyhanko.config.errorsr   Zpyhanko.pdf_utils.miscr   __all__Enumr   r	   INFOr*   r    r   r(   r
   r   r   r   r   <module>   s   
