
    _)8                        d Z ddlZddlZddlZddlZddlmZ dZdZg dZ	dZ
d	Zd
ZdZdZej                  ej                   dZed   ZdZefZdZdZeeiZdZdZdZediZdZddeddgZdZ ee      Z  e!e ee      dz         D  cg c]
  }  e"|        c} ez   dgz   Z#eddjI                  e      dede#djI                  e ee            d edd!diZ%d" Z&d,d#Z'd$ddddd%d%d%dded%dd%fd&Z(	 	 	 d-d'Z)d( Z* G d) d*e+      Z,d+ Z-yc c} w ).a>  Project logging configuration.

Project-scope constants may reside here, but more importantly, some setup here
will provide a logging infrastructure for all of the project's modules.
Individual modules and classes may provide separate configuration on a more
local level, but this will at least provide a foundation.

    N   )__version__zVince Reuterzvreuter@virginia.edu)add_logging_optionslogger_via_cliinit_loggersetup_loggerAbsentOptionExceptionLOGGING_CLI_OPTDATAz%(message)szK%(levelname).4s %(asctime)s | %(name)s:%(module)s:%(lineno)d > %(message)s zI%(levelname)s %(asctime)s | %(name)s:%(module)s:%(lineno)d > %(message)s z%H:%M:%Slogmuse)OUTERRr   INFO   TRACEsilent	verbositylogdevdevmodeWARNCRITICALERRORDEBUGWARNING
store_truezSilence logging. Overrides {}.)actionhelpVz6Set logging level ({}-{} or logging module level name))metavarchoicesr   z)Expand content of logging message format.c                     t         j                         D ]'  \  }} | j                  dj                  |      fi | ) | S )a4  
    Augment a CLI argument parser with this package's logging options.

    :param argparse.ArgumentParser parser: CLI options and argument parser to
        augment with logging options.
    :return argparse.ArgumentParser: the input argument, supplemented with this
        package's logging options.
    z--{})r
   itemsadd_argumentformat)parseroptnameoptdatas      +lib/python3.12/site-packages/logmuse/est.pyr   r   A   sD     0557 ?FMM'2>g>?M    c                    i }t         j                         D ]9  }|j                  d      }	 t        | |      }||t        j                  ||      <   ; |j                  |       t        di |S # t        $ r |rt        |      Y pw xY w)a<  
    Convenience function creating a logger.

    This module provides the ability to augment a CLI parser with
    logging-related options/arguments so that client applications do not need
    intimate knowledge of the implementation. This function completes that
    lack of burden, parsing values for the options supplied herein.

    :param argparse.Namespace opts: command-line options/arguments.
    :param bool strict: whether to raise an exception
    :return logging.Logger: configured logger instance.
    :raise pararead.logs.AbsentOptionException: if one of the expected options
        isn't available in the given Namespace, and the argument to the strict
        parameter is True. Such a case suggests that a client application
        didn't use this module to add the expected logging options to a parser.
    - )
r
   keyslstripgetattrPARAM_BY_OPTNAMEgetAttributeErrorr	   updater   )optsstrictkwargslogs_cli_argsr%   nameoptvals          r'   r   r   O   s    ( M&++- H~~c"		HT4(F BHM*..w=>H  '''  	+G44	s   A//BB Fc                   	 |du rC|rt        j                  d       | rW| dk7  rRt        j                  dj                  |              n-| xs t        } |du r| dk(  rt	        dj                  |             t
        j                         D ]  \  }}t        j                  ||        t        j                  |       }g |_	        ||_
        |r%|j                  t        j                                |S ||t	        dj                  ||            |	 t        |      }nt        |xs t               }	 t#        |t$              rt'        t         |      n|}|j)                  |       g }|ryt.        j0                  j3                  |      }t.        j0                  j5                  |      st/        j6                  |       |j9                  t        j:                  |d	
             |s|sl|s	t<        }|}n=|t>        j@                  t>        jB                  fv r|}n	 tD        |j                            }|j9                  t        jL                  |             |t         jN                  k  	r	fdnfd}d|
i}|r_t>        jP                  }|dk  rEt        j                  dj                  |jR                  |jT                  |jV                               n||d<   |D ]O  }|jY                  t        jZ                   ||      fi |       |j)                  |       |j                  |       Q |j]                  d|j^                  t        t`               |S # t        $ r |j                         }Y @w xY w# t*        $ rH t        j,                  dt%        |      t%        t                      t         }|j)                  |       Y `w xY w# tF        tH        f$ r) tK        dj                  |t<                     t<        }Y w xY w)a  
    Establish and configure primary logger.

    This is intended to be called just once per "session", with a "session"
    defined as an invocation of the main workflow, a testing session, or an
    import of the primary abstractions, e.g. in an interactive iPython session.

    :param str name: name for the logger
    :param int | str level: minimal level of messages to listen for
    :param str stream: standard stream to use as log destination. The default
        behavior is to write logs to stdout, even if null is passed here. This
        is to allow a CLI argument as input to stream parameter, where it may be
        undesirable to require specification of a default value in the client
        application in order to prevent passing None if no CLI option value
        is given. To disable standard stream logging, set 'silent' to True
        or pass a path to a file to which to write logs, which gets priority
        over a standard stream as the destination for log messages.
    :param str | FileIO[str] logfile: path to filesystem location to use as
        logs destination. if provided, this mutes standard stream logging.
    :param bool make_root: whether to use returned logger as root logger. This
        means the name will be 'root' and that messages will not propagate.
    :param bool propagate: whether to allow messages from this logger to reach
        parent logger(s).
    :param bool silent: whether to silence logging; this is only guaranteed for
        messages from this logger and for those from loggers beneath this one
        in the runtime hierarchy without no separate handling. Propagation must
        also be turned off separately--if this is not the root logger--in
        order to ensure that messages are not handled and emitted from a
        potential parent to the logger built here.
    :param bool devmode: whether to log in development mode; possibly among
        other behavioral changes to logs handling, use a more information-rich
        message format template.
    :param int | str verbosity: alternate mode of expression for logging level
        that better accords with intuition about how to convey this. It's
        positively associated with message volume rather than negatively so, as
        logging level is. This takes precedence over 'level' if both are present.
    :param str fmt: message format/template.
    :param str datefmt: format/template for time component of a log record.
    :param bool plain_format: force use of plain message format, even if
        in development mode (debug level)
    :param str style: string indicating message formatting strategy; refer to
        https://docs.python.org/3/howto/logging-cookbook.html#use-of-alternative-formatting-styles;
        only valid in Python3.2+
    :param bool use_full_names: don't truncate level names
    :return logging.Logger: configured Logger instance
    :raise ValueError: if attempting to name explicitly non-root logger with
        a root name, or if both level and verbosity are specified
    Tz(Propagation from root logger is nonsenserootz,Requested root logger with non-root name: {}Fz,Requested non-root logger with root name: {}zDCannot specify both level and verbosity; got {} and {}, respectivelyz2Can't set logging level to %s; instead using: '%s'w)modez%Invalid stream location: {}; using {}c                     S Nr+   )_fmts    r'   <lambda>zinit_logger.<locals>.<lambda>   s     r(   c                 l    ss"s t        | t        j                        st        S rt        S t
        S r?   )
isinstanceloggingFileHandlerBASIC_LOGGING_FORMATFULL_DEV_LOGGING_FMTDEV_LOGGING_FMT)hdlrr   fineplain_formatuse_full_namess    r'   rB   zinit_logger.<locals>.<lambda>   s3    \
41D1D E * !/	 5D r(   datefmt)      zEInsufficient Python version to specify logging format style: {}.{}.{}stylez#Configured logger '%s' using %s v%s)1rE   warningr#   PACKAGE_NAME
ValueErrorCUSTOM_LEVELSr!   addLevelName	getLoggerhandlers	propagate
addHandlerNullHandlerintupper_level_from_verbosityLOGGING_LEVELrD   strr.   setLevel	ExceptionerrorospathdirnameexistsmakedirsappendrF   DEFAULT_STREAMsysstderrstdoutSTREAMSr1   KeyErrorprintStreamHandlerr   version_infomajorminormicrosetFormatter	Formatterdebugr7   r   )r7   levelstreamlogfile	make_rootrY   r   r   r   rA   rN   rL   rQ   rM   
level_namelevel_valueloggerrX   logfile_folder
stream_locget_fmt
fmt_kwargsvershrK   s          ` ` ` `          @r'   r   r   u   s   l DOOFGDFNOO !!'/ #|$&.>EEdKM M $1#6#6#8 6
K[*56 t$FFO F '--/0 Y2 ,,2F5),DF 	F			"JE &i&@=A+5eS+A'u H1ww~~n-KK' 	++G#>?W#FJ

CJJ//J,$V\\^4
 	--j9:GMM!D!$}	F 
 W%J&=OO!6$**djj$**EG #(Jw 	w((BzBC	

5! LL6lK9 M  	"KKME	"  J%j#m"4	6	2 #H- , =fV^46+
,s7   M 83M; O M87M8;AOO4PPc                 d    t        j                  dt               t        | |||||||||	|
||      S )z7 Old alias for init_logger for backwards compatibility z/Please use init_logger in place of setup_logger)warningswarnDeprecationWarningr   )r7   ry   rz   r{   r|   rY   r   r   r   rA   rN   rL   rQ   s                r'   r   r     sA    
 MMC$&eVWiC,G Gr(   c                    	 t        |       } t        | t              rq| j                         }|j	                  t
              rt
        }|t        vr.t        dj                  | dj                  t                          t        t        |      S t        | t               rt        | dz
     S t        dj                  | t        |                   #  Y xY w)a  
    Translation of verbosity into logging level.

    Log message count monotonically increases in verbosity
    while it decreases in logging level, making verbosity
    a more intuitive specification mechanism for users.

    :param int | str verbosity: small integral value representing a relative
        measure of interest in seeing messages about program execution,
        or the name of a Python builtin logging level
    :return int: numeric logging level in accordance with Python builtin logging
    z1Invalid logging verbosity ('{}'); choose from: {}z, r   z,Verbosity must be string or int; got {} ({}))r\   rD   r`   r]   
startswith
_WARN_REPRLEVEL_BY_VERBOSITYrT   r#   joinr.   rE   	TypeErrortype)r   vs     r'   r^   r^     s    	N	 )S!OO<<
#A&&VItyy1C'DEG G w""	Is	#!)a-00F	4	?;= 	=s   C Cc                   "     e Zd ZdZ fdZ xZS )r	   zB Exception subtype suggesting that client should add log options. c                     dj                  |dj                  t        t        j                              }t        t        |   |       y )Nz]'{}' not in the parsed options; was {} used to add CLI logging options to an argument parser?z{}.{})r#   __name__r   superr	   __init__)selfmissing_optnamelikely_reason	__class__s      r'   r   zAbsentOptionException.__init__>  sE    I "5">">)@ A 	 	#T3MBr(   )r   
__module____qualname____doc__r   __classcell__)r   s   @r'   r	   r	   <  s    LC Cr(   r	   c                 F    t        j                  |       fd_        S )z
    Return a logger with given name, equipped with custom method.

    :param str name: name for the logger to get/create.
    :return logging.Logger: named, custom logger instance.
    c                 2     j                   d| g|i |S )Nr   )log)msgargsr5   ls      r'   rB   zget_logger.<locals>.<lambda>Q  s    UQUU1c-KD-KF-K r(   )rE   rW   whisper)r7   r   s    @r'   
get_loggerr   I  s!     	$AKAIHr(   )T)r9   NNNNFFFNNNFN).r   rE   rd   rk   r   _versionr   
__author__	__email____all__rG   rI   rH   DEFAULT_DATE_FMTrS   rm   rl   rn   rj   r_   LOGGING_LOCATIONSTRACE_LEVEL_VALUETRACE_LEVEL_NAMErU   SILENCE_LOGS_OPTNAMEVERBOSITY_OPTNAMEDEVMODE_OPTNAMEr/   r   r   _MIN_VERBOSITYlen_MAX_VERBOSITYranger`   _VERBOSITY_CHOICESr#   r
   r   r   r   r   r^   rb   r	   r   )xs   0r'   <module>r      s    	 
  !
"	K % _b  **SZZ
0#&   !#45  #Y/ 
 
 ':vwG '(NC0B,Ca,GHJc!f J'(+4+6 
 0778IJL #5HF>3'9#:;= ;= #(N tD$%uD*:5	Wv 37?DJN	G=BCI C	uJs   D	