o |nh=@sdZddlZddlZddlZddlZddlZdZeje e fZ eje e fZ eje e fZ ej dkr8ejdZne Zdddd d d Zd d ddZGdddZGdddejZGdddZeZdS)zThe ColoredFormatter class.N)default_log_colorsColoredFormatterLevelFormatterTTYColoredFormatter)%{$whitegreenyellowredbold_red)DEBUGINFOWARNINGERRORCRITICALz/%(log_color)s%(levelname)s:%(name)s:%(message)sz'{log_color}{levelname}:{name}:{message}z+${log_color}${levelname}:${name}:${message}c@s(eZdZdZdejdeddfddZdS) ColoredRecordz Wraps a LogRecord, adding escape codes to the internal dict. The internal dict is used when formatting the message (by the PercentStyle, StrFormatStyle, and StringTemplateStyle classes). recordescapesreturnNcCs|j|j|j|dSN)__dict__update)selfrrrJ/usr/local/bin/dhwp/env/lib/python3.10/site-packages/colorlog/formatter.py__init__3szColoredRecord.__init__)__name__ __module__ __qualname____doc__logging LogRecord EscapeCodesr rrrrr+srcseZdZdZ           d"dejedejeded ejed e d eje d e d ejej de de dejej eej fddffdd Zdejdeffdd ZdedefddZddZed ededefddZdededefd d!ZZS)#rz A formatter that allows colors to be placed in the format string. Intended to help in creating more readable logging output. Nr TFfmtdatefmtstyle log_colorsresetsecondary_log_colorsvalidatestreamno_color force_colordefaultsrc s|durt|n|}tjdkrtj||||| dntjdkr*t||||nt||||dur8|nt|_|durA|ni|_||_||_ | |_ | |_ dS)a2 Set the format and colors the ColoredFormatter will use. The ``fmt``, ``datefmt``, ``style``, and ``default`` args are passed on to the ``logging.Formatter`` constructor. The ``secondary_log_colors`` argument can be used to create additional ``log_color`` attributes. Each key in the dictionary will set ``{key}_log_color``, using the value to select from a different ``log_colors`` set. :Parameters: - fmt (str): The format string to use. - datefmt (str): A format string for the date. - log_colors (dict): A mapping of log level names to color names. - reset (bool): Implicitly append a color reset to all records unless False. - style ('%' or '{' or '$'): The format style to use. - secondary_log_colors (dict): Map secondary ``log_color`` attributes. (*New in version 2.6.*) - validate (bool) Validate the format string. - stream (typing.IO) The stream formatted messages will be printed to. Used to toggle colour on non-TTY outputs. Optional. - no_color (bool): Disable color output. - force_color (bool): Enable color output. Takes precedence over `no_color`. N)r )r2r) default_formatssys version_infosuperr rr+r-r,r/r0r1) rr(r)r*r+r,r-r.r/r0r1r2 __class__rrr ?s0   zColoredFormatter.__init__rcs2||j}t||}t|}|||}|S)z&Format a message from a record object.)_escape_code_map levelnamerr7 formatMessage _append_reset)rrrwrappermessager8rrr<s    zColoredFormatter.formatMessageitemcCslitjj}|d||j||jD]\}}|d||||q|r4dd|D}|S)z Build a map of keys to escape codes for use in message formatting. If _blank_escape_codes() returns True, all values will be an empty string. log_colorz %s_log_colorcSsi|]}|dqS)r).0keyrrr sz5ColoredFormatter._escape_code_map..) colorlog escape_codes setdefault_get_escape_coder+r-items_blank_escape_codeskeys)rr@codesnamecolorsrrrr:s z!ColoredFormatter._escape_code_mapcCsD|jsdtjvr dS|jsdtjvrdS|jdur |js dSdS)zAReturn True if we should be prevented from printing escape codes. FORCE_COLORFNO_COLORTN)r1osenvironr0r/isatty)rrrrrKsz$ColoredFormatter._blank_escape_codescCstj||dS)zAExtract a color sequence from a mapping, and return escape codes.rB)rFrG parse_colorsget)r+r@rrrrIsz!ColoredFormatter._get_escape_coder?rcCs$|d}|jr||s||7}|S)zFAdd a reset code to the end of the message, if it's not already there.r,)r,endswith)rr?rreset_escape_coderrrr=szColoredFormatter._append_reset) NNr NTNTNFFN)r!r"r#r$typingOptionalstr _FormatStyle LogColorsboolSecondaryLogColorsIOMappingAnyr r%r&r<r'r:rK staticmethodrIr= __classcell__rrr8rr8sX     B rc@sFeZdZdZdejeefdejddfddZde j defd d Z dS) rzDAn extension of ColoredFormatter that uses per-level format strings.r(kwargsrNc sfdd|D|_dS)a Configure a ColoredFormatter with its own format string for each log level. Supports fmt as a dict. All other args are passed on to the ``colorlog.ColoredFormatter`` constructor. :Parameters: - fmt (dict): A mapping of log levels (represented as strings, e.g. 'WARNING') to format strings. (*New in version 2.7.0) (All other parameters are the same as in colorlog.ColoredFormatter) Example: formatter = colorlog.LevelFormatter( fmt={ "DEBUG": "%(log_color)s%(message)s (%(module)s:%(lineno)d)", "INFO": "%(log_color)s%(message)s", "WARNING": "%(log_color)sWRN: %(message)s (%(module)s:%(lineno)d)", "ERROR": "%(log_color)sERR: %(message)s (%(module)s:%(lineno)d)", "CRITICAL": "%(log_color)sCRT: %(message)s (%(module)s:%(lineno)d)", } ) cs$i|]\}}|tdd|iqS)r(r)r)rClevelfrerrrEsz+LevelFormatter.__init__..N)rJ formatters)rr(rerrhrr s  zLevelFormatter.__init__rcCs|j|j|Sr)rir;format)rrrrrrjszLevelFormatter.format) r!r"r#r$rYrar[rbr r%r&rjrrrrrs"r)r$r%rRr5rYcolorlog.escape_codesrF__all__rar[r'r]r_r6Literalr\rr4r Formatterrrrrrrrs6    {&