3 گa�: � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlm Z ddl mZ ddl mZ ddl m Z ddl mZ ddl mZ dd lmZ dd lmZ ddlmZ ddlmZ dd lmZ ddlmZ dZdZeje�Zdd�dd�Zej dd�dd�Z!ej e"e"eej#e"f d�dd�Z$G dd� dej%�Z&G dd� dej'j(�Z(G dd� dej%�Z)e(eedd �d!d"�Z*ee+ e+e e,e,e"dd#�d$d%�Z-e"dd&�d'd(�Z.dS ))a� Logging utilities for Certbot. The best way to use this module is through `pre_arg_parse_setup` and `post_arg_parse_setup`. `pre_arg_parse_setup` configures a minimal terminal logger and ensures a detailed log is written to a secure temporary file if Certbot exits before `post_arg_parse_setup` is called. `post_arg_parse_setup` relies on the parsed command line arguments and does the full logging setup with terminal and rotating file handling as configured by the user. Any logged messages before `post_arg_parse_setup` is called are sent to the rotating file handler. Special care is taken by both methods to ensure all errors are logged and properly flushed before program exit. The `logging` module is useful for recording messages about about what Certbot is doing under the hood, but do not necessarily need to be shown to the user on the terminal. The default verbosity is WARNING. The preferred method to display important information to the user is to use `certbot.display.util` and `certbot.display.ops`. � N)� TracebackType)�Any)�IO)�Optional)�Tuple)�Type)�messages)� configuration)�errors)�util)� constants)�osz%(message)sz.%(asctime)s:%(levelname)s:%(name)s:%(message)s)�returnc C s� t � } | jtjt�� | jtj� t| �}t� }|jtjt �� |jt j� tj� }|jtj� |j |� |j |� tjtj� tjt|dtjkdtjkp�dtjk| jd�t_dS )a� Setup logging before command line arguments are parsed. Terminal logging is setup using `certbot._internal.constants.QUIET_LOGGING_LEVEL` so Certbot is as quiet as possible. File logging is setup so that logging messages are buffered in memory. If Certbot exits before `post_arg_parse_setup` is called, these buffered messages are written to a temporary file. If Certbot doesn't exit, `post_arg_parse_setup` writes the messages to the normal log files. This function also sets `logging.shutdown` to be called on program exit which automatically flushes logging handlers and `sys.excepthook` to properly log/display fatal exceptions. z--debugz--quietz-q)�debug�quiet�log_pathN)�TempHandler�setFormatter�logging� Formatter�FILE_FMT�setLevel�DEBUG� MemoryHandler�ColoredStreamHandler�CLI_FMTr �QUIET_LOGGING_LEVEL� getLogger� addHandlerr Zatexit_registerZshutdown� functools�partial�pre_arg_parse_except_hook�sys�argv�path� excepthook)�temp_handler�memory_handlerZstream_handler�root_logger� r) �/usr/lib/python3.6/log.py�pre_arg_parse_setup5 s"