o ?Ogh9 @sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m ZgdZddlZdZdZdZd ZeZd Zd Zd Zd Zd ZeZd Zd ZeZdZdZ dZ!edededede de!diZ"eeeeeee e!dZ#ddZ$ddZ%e&edrddZ'nddZ'ej()e%j*j+Z,d d!Z-e.Z/d"d#Z0d$d%Z1e&ed&sd'd(Z2ne3Z4d)d(Z2d*d+Z5ej6e0e5e1d,Gd-d.d.e7Z8e8a9d/d0Z:d1d2Z;d3d4ZGd7d8d8e>Z?Gd9d:d:e>Z@d;ZAe>eAfe?dZBGd?d@d@e7Z e ZCGdAdBdBe7ZDGdCdDdDe7ZEGdEdFdFe7ZFeGZHgZIdGdHZJdIdJZKGdKdLdLeFZLGdMdNdNeLZMGdOdPdPeMZNGdQdRdReMZOeOeZPePZQGdSdTdTe7ZRdUdVZSdWdXZTGdYdZdZe7ZUGd[d\d\eFZVGd]d^d^eVZWeVaXGd_d`d`e7ZYeWeZZeZeV_ZeUeVjZeV_[dadbZ\ddcddZ]dedfZ^dgdhZ_didjZ`d dkdldmZadndoZbdpdqZcdrdsZddtduZedvdwZfefdxdyZgeIfdzd{ZhddliZieijehGd|d}d}eLZkdaldd~dZmddZndS)z Logging package for Python. Based on PEP 282 and comments thereto in comp.lang.python. Copyright (C) 2001-2019 Vinay Sajip. All Rights Reserved. To use, simply 'import logging' and log away! N)Template) Formatter)* BASIC_FORMATBufferingFormatterCRITICALDEBUGERRORFATAL FileHandlerFilterrHandlerINFO LogRecordLogger LoggerAdapterNOTSET NullHandler StreamHandlerWARNWARNING addLevelName basicConfigcaptureWarningscriticaldebugdisableerror exceptionfatal getLevelName getLoggergetLoggerClassinfolog makeLogRecordsetLoggerClassshutdownwarnwarninggetLogRecordFactorysetLogRecordFactory lastResortraiseExceptionsz&Vinay Sajip Z productionz0.5.1.2z07 February 2010T2( rrrr rr)rr rrrr rrcCs4t|}|dur |St|}|dur|Sd|S)a Return the textual or numeric representation of logging level 'level'. If the level is one of the predefined levels (CRITICAL, ERROR, WARNING, INFO, DEBUG) then you get the corresponding string. If you have associated levels with names using addLevelName then the name you have associated with 'level' is returned. If a numeric value corresponding to one of the defined levels is passed in, the corresponding string representation is returned. If a string representation of the level is passed in, the corresponding numeric value is returned. If no matching numeric or string value is passed in, the string 'Level %s' % level is returned. NzLevel %s) _levelToNameget _nameToLevel)levelresultr77/opt/alt/python310/lib64/python3.10/logging/__init__.pyrws  rcCs,tz|t|<|t|<WtdStw)zy Associate 'levelName' with 'level'. This is used when converting levels to text during message formatting. N) _acquireLockr2r4 _releaseLock)r5Z levelNamer7r7r8rs  r _getframecCs tdS)N)sysr;r7r7r7r8s r>cCs(zttytdjjYSw)z5Return the frame object for the caller's stack frame.) Exceptionr=exc_infotb_framef_backr7r7r7r8 currentframes  rDcCsLt|tr |}|St||kr|tvrtd|t|}|Std|f)NzUnknown level: %rz*Level not an integer or a valid string: %r) isinstanceintstrr4 ValueError TypeError)r5rvr7r7r8 _checkLevels   rKcCtrtdSdS)z Acquire the module-level lock for serializing access to shared data. This should be released with _releaseLock(). N)_lockacquirer7r7r7r8r9s r9cCrL)zK Release the module-level lock acquired by calling _acquireLock(). N)rMreleaser7r7r7r8r:s r:register_at_forkcCdSNr7instancer7r7r8_register_at_fork_reinit_lockrUcCs&tz t|WtdStwrR)r9_at_fork_reinit_lock_weaksetaddr:rSr7r7r8rUs cCstD]}|qtdSrR)rW_at_fork_reinitrMZhandlerr7r7r8!_after_at_fork_child_reinit_lockss  r[)ZbeforeZafter_in_childZafter_in_parentc@s,eZdZdZ d ddZddZddZdS) ra A LogRecord instance represents an event being logged. LogRecord instances are created every time something is logged. They contain all the information pertinent to the event being logged. The main information passed in is in msg and args, which are combined using str(msg) % args to create the message field of the record. The record also includes information such as when the record was created, the source line where the logging call was made, and any exception information to be logged. Nc Kst} ||_||_|r#t|dkr#t|dtjjr#|dr#|d}||_t ||_ ||_ ||_ zt j||_t j|jd|_WntttfyV||_d|_Ynw||_d|_| |_||_||_| |_t| t| dd|_|jtd|_t rt!"|_#t!$j|_%nd|_#d|_%t&sd|_'nd|_'t(j)*d} | durz| +j|_'Wn t,yYnwt-rt.t d rt /|_0dSd|_0dS) zK Initialize a logging record with interesting information. rzUnknown moduleNigZ MainProcessZmultiprocessinggetpid)1timenamemsglenrE collectionsabcMappingargsrZ levelnamelevelnopathnameospathbasenamefilenamesplitextmodulerIrHAttributeErrorrAexc_text stack_infolinenoZfuncNamecreatedrFmsecs _startTimeZrelativeCreated logThreads threading get_identthreadZcurrent_threadZ threadNamelogMultiprocessingZ processNamer=modulesr3Zcurrent_processr@ logProcesseshasattrr]process) selfr_r5rgrqr`rerAfuncsinfokwargsctZmpr7r7r8__init__sX"      zLogRecord.__init__cCsd|j|j|j|j|jfS)Nz!)r_rfrgrqr`r~r7r7r8__repr__cs  zLogRecord.__repr__cCst|j}|jr ||j}|S)z Return the message for this LogRecord. Return the message for this LogRecord after merging any user-supplied arguments with the message. )rGr`re)r~r`r7r7r8 getMessagegs  zLogRecord.getMessageNN)__name__ __module__ __qualname____doc__rrrr7r7r7r8rs  H rcCs|adS)z Set the factory to be used when instantiating a log record. :param factory: A callable which will be called to instantiate a log record. N_logRecordFactory)factoryr7r7r8r*xsr*cCtS)zH Return the factory to be used when instantiating a log record. rr7r7r7r8r)sr)c Cs&tdddddddd}|j||S)z Make a LogRecord whose attributes are defined by the specified dictionary, This function is useful for converting a logging event received over a socket connection (which is sent as a dictionary) into a LogRecord instance. Nrr7)r__dict__update)dictrJr7r7r8r$s r$c@sTeZdZdZdZdZedejZ ddddZ d d Z d d Z d dZ ddZdS) PercentStylez %(message)sz %(asctime)sz %(asctime)z5%\(\w+\)[#0+ -]*(\*|\d+)?(\.(\*|\d+))?[diouxefgcrsa%]NdefaultscCs|p|j|_||_dSrR)default_format_fmt _defaults)r~fmtrr7r7r8rs  zPercentStyle.__init__cCs|j|jdkS)Nrrfindasctime_searchrr7r7r8usesTimeszPercentStyle.usesTimecCs*|j|jstd|j|jdfdS)z>Validate the input format, ensure it matches the correct stylez"Invalid format '%s' for '%s' stylerN)validation_patternsearchrrHrrr7r7r8validateszPercentStyle.validatecCs&|j}r ||jB}n|j}|j|SrR)rrrr~recordrvaluesr7r7r8_formats   zPercentStyle._formatc Cs2z||WSty}ztd|d}~ww)Nz(Formatting field not found in record: %s)rKeyErrorrH)r~rer7r7r8formats   zPercentStyle.format)rrrrasctime_formatrrecompileIrrrrrrr7r7r7r8rs rc@s@eZdZdZdZdZedejZ edZ ddZ dd Z d S) StrFormatStylez {message}z {asctime}z{asctimezF^(.?[<>=^])?[+ -]?#?0?(\d+|{\w+})?[,_]?(\.(\d+|{\w+}))?[bcdefgnosx%]?$z^(\d+|\w+)(\.\w+|\[[^]]+\])*$cC.|j}r ||jB}n|j}|jjdi|SNr7)rrrrrr7r7r8r  zStrFormatStyle._formatc Cst}z||}|r|z ||W||S|w|S)a< Conditionally emit the specified logging record. Emission depends on filters which may have been added to the handler. Wrap the actual emission of the record with acquisition/release of the I/O thread lock. Returns whether the filter passed the record for emission. )rrNrrO)r~rrJr7r7r8handles   zHandler.handlecC ||_dS)z5 Set the formatter for this handler. N)r rr7r7r8 setFormatterrzHandler.setFormattercCr)z Ensure all logging output has been flushed. This version does nothing and is intended to be implemented by subclasses. Nr7rr7r7r8flushsz Handler.flushcCsRtz!d|_|jr|jtvrt|j=WtdSWtdSWtdStw)a% Tidy up any resources used by the handler. This version removes the handler from an internal map of handlers, _handlers, which is used for handler lookup by name. Subclasses should ensure that this gets called from overridden close() methods. TN)r9r r rr:rr7r7r8rs    z Handler.closecCsBtrtjrt\}}}zzvtjdt|||dtjtjd|j}|rFtj |j j t dkrF|j}|rFtj |j j t dks5|rQtj|tjdn tjd|j|jfztjd|j|jfWntystytjdYnwWn tyYnwW~~~dSW~~~dS~~~wdSdS) aD Handle errors which occur during an emit() call. This method should be called from handlers when an exception is encountered during an emit() call. If raiseExceptions is false, exceptions get silently ignored. This is what is mostly wanted for a logging system - most users will not care about errors in the logging system, they are more interested in application errors. You could, however, replace this with a custom handler if you wish. The record which was being processed is passed in to this method. z--- Logging error --- Nz Call stack: rfilezLogged from file %s, line %s zMessage: %r Arguments: %s zwUnable to print the message and arguments - possible formatting error. Use the traceback above to help find the error. )r,r=stderrrAwriterrrBrhridirnamef_code co_filename__path__rC print_stackrkrqr`reRecursionErrorr@OSError)r~rtvrframer7r7r8 handleErrorsN       zHandler.handleErrorcCst|j}d|jj|fS)Nz <%s (%s)>)rr5rrrr7r7r8rs zHandler.__repr__N)rrrrrrrrpropertyr_rrYrNrOrrrrrrrr.rr7r7r7r8r _s&      /r c@s>eZdZdZdZdddZddZdd Zd d Zd d Z dS)rz A handler class which writes logging records, appropriately formatted, to a stream. Note that this class does not close the stream, as sys.stdout or sys.stderr may be used. rNcCs"t||dur tj}||_dS)zb Initialize the handler. If stream is not specified, sys.stderr is used. N)r rr=r"streamr~r0r7r7r8r*s  zStreamHandler.__init__cCsZ|z#|jrt|jdr!|jW|dSW|dSW|dS|w)z% Flushes the stream. rN)rNr0r|rrOrr7r7r8r5s   zStreamHandler.flushcCs\z||}|j}|||j|WdStyty-||YdSw)a Emit a record. If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline. If exception information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream has an 'encoding' attribute, it is used to determine how to do the output to the stream. N)rr0r# terminatorrr)r@r.)r~rr`r0r7r7r8r@s   zStreamHandler.emitcCsH||jur d}|S|j}|z|||_W||S|w)z Sets the StreamHandler's stream to the specified value, if it is different. Returns the old stream, if the stream was changed, or None if it wasn't. N)r0rNrrO)r~r0r6r7r7r8 setStreamVs   zStreamHandler.setStreamcCs>t|j}t|jdd}t|}|r|d7}d|jj||fS)Nr_r z <%s %s(%s)>)rr5getattrr0rGrr)r~r5r_r7r7r8rjs zStreamHandler.__repr__rR) rrrrr2rrrr3rr7r7r7r8r!s    rc@s:eZdZdZdddZddZd d Zd d Zd dZdS)r zO A handler class which writes formatted logging records to disk files. aNFcCsvt|}tj||_||_||_d|vrt||_||_ ||_ t |_ |r1t |d|_dSt||dS)zO Open the specified file and use it as the stream for logging. bN)rhfspathriabspath baseFilenamemodeencodingr text_encodingerrorsdelayopen _builtin_openr rr0r_open)r~rkr;r<r?r>r7r7r8rxs    zFileHandler.__init__c Cs|z?z1|jr0z|W|j}d|_t|dr|n|j}d|_t|dr/|wwWt|nt|wW|dS|w)z$ Closes the stream. Nr)rNr0rr|rrrOr1r7r7r8rs&    zFileHandler.closecCs|j}||j|j|j|jdS)zx Open the current base file with the (original) mode and encoding. Return the resulting stream. r<r>)rAr:r;r<r>)r~Z open_funcr7r7r8rBs zFileHandler._opencCs>|jdur|jdks |js||_|jrt||dSdS)a- Emit a record. If the stream was not opened because 'delay' was specified in the constructor, open it before calling the superclass's emit. If stream is not open, current mode is 'w' and `_closed=True`, record will not be emitted (see Issue #42378). Nw)r0r;r rBrrrr7r7r8rs  zFileHandler.emitcCst|j}d|jj|j|fSNz <%s %s (%s)>)rr5rrr:rr7r7r8rs zFileHandler.__repr__)r6NFN) rrrrrrrBrrr7r7r7r8r ts  r c@s(eZdZdZefddZeddZdS)_StderrHandlerz This class is like a StreamHandler using sys.stderr, but always uses whatever sys.stderr is currently set to rather than the value of sys.stderr at handler construction time. cCst||dS)z) Initialize the handler. N)r rrr7r7r8rz_StderrHandler.__init__cCstjSrR)r=r"rr7r7r8r0z_StderrHandler.streamN)rrrrrrr/r0r7r7r7r8rFs  rFc@ eZdZdZddZddZdS) PlaceHolderz PlaceHolder instances are used in the Manager logger hierarchy to take the place of nodes for which no loggers have been defined. This class is intended for internal use only and not as part of the public API. cCs|di|_dS)zY Initialize with the specified logger being a child of this placeholder. N loggerMapr~aloggerr7r7r8rrzPlaceHolder.__init__cCs||jvr d|j|<dSdS)zJ Add the specified logger as a child of this placeholder. NrKrMr7r7r8rs zPlaceHolder.appendN)rrrrrrr7r7r7r8rJ rJcCs(|tkrt|tstd|j|adS)z Set the class to be used when instantiating a logger. The class should define __init__() such that only a name argument is required, and the __init__() should call Logger.__init__() (logger not derived from logging.Logger: N)r issubclassrIr _loggerClass)klassr7r7r8r%s  r%cCr)zB Return the class to be used when instantiating a logger. )rRr7r7r7r8r!rr!c@sbeZdZdZddZeddZejddZddZd d Z d d Z d dZ ddZ ddZ dS)Managerzt There is [under normal circumstances] just one Manager instance, which holds the hierarchy of loggers. cCs(||_d|_d|_i|_d|_d|_dS)zT Initialize the manager with the root node of the logger hierarchy. rFN)rootremittedNoHandlerWarning loggerDict loggerClasslogRecordFactory)r~Zrootnoder7r7r8rs  zManager.__init__cCrrR)_disablerr7r7r8rrHzManager.disablecCst||_dSrR)rKrZr~valuer7r7r8rscCsd}t|ts tdtzL||jvr;|j|}t|tr:|}|jp$t|}||_||j|<| ||| |n|jp?t|}||_||j|<| |Wt |SWt |St w)a Get a logger with the specified name (channel name), creating it if it doesn't yet exist. This name is a dot-separated hierarchical name, such as "a", "a.b", "a.b.c" or similar. If a PlaceHolder existed for the specified name [i.e. the logger didn't exist but a child of it did], replace it with the created logger and fix up the parent/child references which pointed to the placeholder to now point to the logger. NzA logger name must be a string) rErGrIr9rWrJrXrRmanager_fixupChildren _fixupParentsr:)r~r_rJphr7r7r8r #s2         zManager.getLoggercCs*|tkrt|tstd|j||_dS)zY Set the class to be used when instantiating a logger with this Manager. rPN)rrQrIrrX)r~rSr7r7r8r%Es   zManager.setLoggerClasscCr)zg Set the factory to be used when instantiating a log record with this Manager. N)rY)r~rr7r7r8r*Os zManager.setLogRecordFactorycCs|j}|d}d}|dkrD|sD|d|}||jvr#t||j|<n|j|}t|tr0|}n|||dd|d}|dkrD|r|sI|j}||_dS)z Ensure that there are either loggers or placeholders all the way from the specified logger to the root of the logger hierarchy. rNrr\) r_rfindrWrJrErrrUparent)r~rNr_irJZsubstrobjr7r7r8r_Vs           zManager._fixupParentscCsD|j}t|}|jD]}|jjd||kr|j|_||_q dS)zk Ensure that children of the placeholder ph are connected to the specified logger. N)r_rarLrrb)r~r`rNr_Znamelencr7r7r8r^nszManager._fixupChildrencCs@t|jD] }t|tr|jq|jjtdS)zj Clear the cache for all loggers in loggerDict Called when level changes are made N) r9rWrrEr_cacheclearrUr:r~loggerr7r7r8 _clear_cache{s    zManager._clear_cacheN)rrrrrr/rsetterr r%r*r_r^rjr7r7r7r8rT s  "  rTc@seZdZdZefddZddZddZdd Zd d Z d d Z ddZ ddddZ ddZ ddZddZd7ddZ d8dd Z  d9d!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6ZdS):rar Instances of the Logger class represent a single logging channel. A "logging channel" indicates an area of an application. Exactly how an "area" is defined is up to the application developer. Since an application can have any number of areas, logging channels are identified by a unique string. Application areas can be nested (e.g. an area of "input processing" might include sub-areas "read CSV files", "read XLS files" and "read Gnumeric files"). To cater for this natural nesting, channel names are organized into a namespace hierarchy where levels are separated by periods, much like the Java or Python package namespace. So in the instance given above, channel names might be "input" for the upper level, and "input.csv", "input.xls" and "input.gnu" for the sub-levels. There is no arbitrary limit to the depth of nesting. cCs<t|||_t||_d|_d|_g|_d|_i|_ dS)zJ Initialize the logger with a name and an optional level. NTF) rrr_rKr5rb propagaterdisabledrf)r~r_r5r7r7r8rs   zLogger.__init__cCst||_|jdS)zW Set the logging level of this logger. level must be an int or a str. N)rKr5r]rjrr7r7r8rs zLogger.setLevelcO(|tr|jt||fi|dSdS)z Log 'msg % args' with severity 'DEBUG'. To pass exception information, use the keyword argument exc_info with a true value, e.g. logger.debug("Houston, we have a %s", "thorny problem", exc_info=1) N) isEnabledForr_logr~r`rerr7r7r8r z Logger.debugcOrn)z Log 'msg % args' with severity 'INFO'. To pass exception information, use the keyword argument exc_info with a true value, e.g. logger.info("Houston, we have a %s", "interesting problem", exc_info=1) N)ror rprqr7r7r8r"rrz Logger.infocOrn)z Log 'msg % args' with severity 'WARNING'. To pass exception information, use the keyword argument exc_info with a true value, e.g. logger.warning("Houston, we have a %s", "bit of a problem", exc_info=1) N)rorrprqr7r7r8r(rrzLogger.warningcO*tdtd|j|g|Ri|dSNz6The 'warn' method is deprecated, use 'warning' insteadr?warningsr'DeprecationWarningr(rqr7r7r8r'z Logger.warncOrn)z Log 'msg % args' with severity 'ERROR'. To pass exception information, use the keyword argument exc_info with a true value, e.g. logger.error("Houston, we have a %s", "major problem", exc_info=1) N)rorrprqr7r7r8rrrz Logger.errorTrAcOs |j|g|Rd|i|dS)zU Convenience method for logging an ERROR with exception information. rANrr~r`rArerr7r7r8rs zLogger.exceptioncOrn)z Log 'msg % args' with severity 'CRITICAL'. To pass exception information, use the keyword argument exc_info with a true value, e.g. logger.critical("Houston, we have a %s", "major disaster", exc_info=1) N)rorrprqr7r7r8rrrzLogger.criticalcOs|j|g|Ri|dS)z@ Don't use this method, use critical() instead. Nrrqr7r7r8rsz Logger.fatalcOsBt|ts tr tddS||r|j|||fi|dSdS)z Log 'msg % args' with the integer severity 'level'. To pass exception information, use the keyword argument exc_info with a true value, e.g. logger.log(level, "We have a %s", "mysterious problem", exc_info=1) zlevel must be an integerN)rErFr,rIrorpr~r5r`rerr7r7r8r#s  z Logger.logFr\c Cst}|dur |j}|}|r|dkr|j}|d8}|r|dks|s#|}d}t|drp|j}tj|j}|tkr<|j}q%d}|rdt } | dt j || d| }|ddkr`|dd}| |j|j|j|f} |S|S) z Find the stack frame of the caller so that we can note the source file name, line number and function name. Nr\)(unknown file)r(unknown function)Nr%zStack (most recent call last): r rr)rDrCr|r%rhrinormcaser&_srcfilerrr#rr(rrf_linenoco_name) r~rp stacklevelrZorig_frJcorkrrr7r7r8 findCaller s:      zLogger.findCallerNc CsZt||||||||| } | dur+| D]} | dvs| | jvr#td| | | | j| <q| S)zr A factory method which can be overridden in subclasses to create specialized LogRecords. N)rrz$Attempt to overwrite %r in LogRecord)rrr) r~r_r5fnlnor`rerArextrarrJkeyr7r7r8 makeRecord1s zLogger.makeRecordc Csd}trz |||\} } } }Wntyd\} } } Ynwd\} } } |r=t|tr4t|||jf}n t|ts=t }| |j || | |||| || } | | dS)z Low-level logging routine which creates a LogRecord and then calls all the handlers of this logger to handle the record. N)r~rr) rrrHrE BaseExceptiontype __traceback__tupler=rArr_r) r~r5r`rerArrprrrrrrr7r7r8rp@s"    z Logger._logcCs&|js||r||dSdSdS)z Call the handlers for the specified record. This method is used for unpickled records received from a socket, as well as those created locally. Logger-level filtering is applied. N)rmr callHandlersrr7r7r8rZsz Logger.handlecCs>tz||jvr|j|WtdSWtdStw)z; Add the specified handler to this logger. N)r9rrr:r~hdlrr7r7r8 addHandlerd  zLogger.addHandlercCs>tz||jvr|j|WtdSWtdStw)z@ Remove the specified handler from this logger. N)r9rrr:rr7r7r8 removeHandlerorzLogger.removeHandlercCs6|}d}|r|jrd} |S|js |S|j}|s|S)a See if this logger has any handlers configured. Loop through all handlers for this logger and its parents in the logger hierarchy. Return True if a handler was found, else False. Stop searching up the hierarchy whenever a logger with the "propagate" attribute set to zero is found - that will be the last logger which is checked for the existence of handlers. FT)rrlrb)r~rerJr7r7r8 hasHandlerszs zLogger.hasHandlerscCs|}d}|r&|jD]}|d}|j|jkr||q |js!d}n|j}|s|dkrPtr;|jtjkr9t|dSdStrR|jj sTt j d|j d|j_ dSdSdSdS)a Pass a record to all relevant handlers. Loop through all handlers for this logger and its parents in the logger hierarchy. If no handler was found, output a one-off error message to sys.stderr. Stop searching up the hierarchy whenever a logger with the "propagate" attribute set to zero is found - that will be the last logger whose handlers are called. rr\Nz+No handlers could be found for logger "%s" T)rrfr5rrlrbr+r,r]rVr=r"r#r_)r~rrefoundrr7r7r8rs0        zLogger.callHandlerscCs"|}|r|jr |jS|j}|stS)z Get the effective level for this logger. Loop through this logger and its parents in the logger hierarchy, looking for a non-zero logging level. Return the first one found. )r5rbrrhr7r7r8getEffectiveLevelszLogger.getEffectiveLevelc Cs|jrdSz|j|WStyCtz)|jj|kr$d}|j|<n||k}|j|<Wt|YSWt|YStww); Is this logger enabled for level 'level'? F)rmrfrr9r]rrr:)r~r5Z is_enabledr7r7r8ros$    zLogger.isEnabledForcCs&|j|ur d|j|f}|j|S)ab Get a logger which is a descendant to this one. This is a convenience method, such that logging.getLogger('abc').getChild('def.ghi') is the same as logging.getLogger('abc.def.ghi') It's useful, for example, when the parent logger is named using __name__ rather than a literal string. r)rUrr_r]r )r~suffixr7r7r8getChilds  zLogger.getChildcCs t|}d|jj|j|fSrE)rrrrr_rr7r7r8rs zLogger.__repr__cCs,t|j|urddl}|dt|jffS)Nrzlogger cannot be pickled)r r_pickleZ PicklingError)r~rr7r7r8 __reduce__s  zLogger.__reduce__)Fr\)NNN)NNFr\)rrrrrrrrr"r(r'rrrrr#rrrprrrrrrrorrrr7r7r7r8rs:        %      rc@rI) RootLoggerz A root logger is not that different to any other logger, except that it must have a logging level and there is only one instance of it in the hierarchy. cCst|d|dS)z= Initialize the logger with the name "root". rUN)rrrr7r7r8rszRootLogger.__init__cCstdfSr)r rr7r7r8rszRootLogger.__reduce__N)rrrrrrr7r7r7r8rrOrc@seZdZdZd+ddZddZddZd d Zd d Zd dZ ddZ ddddZ ddZ ddZ ddZddZddZdd Zd,d"d#Zed$d%Zejd&d%Zed'd(Zd)d*ZdS)-rzo An adapter for loggers which makes it easier to specify contextual information in logging output. NcCs||_||_dS)ax Initialize the adapter with a logger and a dict-like object which provides contextual information. This constructor signature allows easy stacking of LoggerAdapters, if so desired. You can effectively pass keyword arguments as shown in the following example: adapter = LoggerAdapter(someLogger, dict(p1=v1, p2="v2")) N)rir)r~rirr7r7r8r s zLoggerAdapter.__init__cCs|j|d<||fS)a Process the logging message and keyword arguments passed in to a logging call to insert contextual information. You can either manipulate the message itself, the keyword args or both. Return the message and kwargs modified (or not) to suit your needs. Normally, you'll only need to override this one method in a LoggerAdapter subclass for your specific needs. r)r)r~r`rr7r7r8r}s zLoggerAdapter.processcO|jt|g|Ri|dS)zA Delegate a debug call to the underlying logger. N)r#rrqr7r7r8r'zLoggerAdapter.debugcOr)zA Delegate an info call to the underlying logger. N)r#r rqr7r7r8r"-rzLoggerAdapter.infocOr)zC Delegate a warning call to the underlying logger. N)r#rrqr7r7r8r(3rzLoggerAdapter.warningcOrsrtrurqr7r7r8r'9rxzLoggerAdapter.warncOr)zB Delegate an error call to the underlying logger. Nr#rrqr7r7r8r>rzLoggerAdapter.errorTrycOs"|jt|g|Rd|i|dS)zF Delegate an exception call to the underlying logger. rANrr{r7r7r8rDs"zLoggerAdapter.exceptioncOr)zD Delegate a critical call to the underlying logger. N)r#rrqr7r7r8rJrzLoggerAdapter.criticalcOs>||r|||\}}|jj||g|Ri|dSdS)z Delegate a log call to the underlying logger, after adding contextual information from this adapter instance. N)ror}rir#r}r7r7r8r#Ps  zLoggerAdapter.logcCr)r)rirorr7r7r8roYs zLoggerAdapter.isEnabledForcCs|j|dS)zC Set the specified level on the underlying logger. N)rirrr7r7r8r_rGzLoggerAdapter.setLevelcCr)zD Get the effective level for the underlying logger. )rirrr7r7r8rerzLoggerAdapter.getEffectiveLevelcCr)z@ See if the underlying logger has any handlers. )rirrr7r7r8rkrzLoggerAdapter.hasHandlersFcCs|jj||||||dS)zX Low-level log implementation, proxied to allow nested logger adapters. )rArrp)rirp)r~r5r`rerArrpr7r7r8rpqszLoggerAdapter._logcC|jjSrRrir]rr7r7r8r]~zLoggerAdapter.managercCs ||j_dSrRrr[r7r7r8r]s cCrrR)rir_rr7r7r8r_rzLoggerAdapter.namecCs&|j}t|}d|jj|j|fSrE)rirrrrr_)r~rir5r7r7r8rs zLoggerAdapter.__repr__rR)NNF)rrrrrr}rr"r(r'rrrr#rorrrrpr/r]rkr_rr7r7r7r8rs0       rcKstz|dd}|dd}|dd}|r+tjddD] }t||qttjdkr|dd}|durId |vrHd |vrHtd n d |vsQd |vrUtd |dur|d d}|d d}|r|d|vrnd}nt |}t ||||d}n |d d}t |}|g}|dd} |dd} | t vrtdd t |dt | d} t| | | } |D]}|jdur|| t|q|dd} | durt| |rd |}td|WtdSWtdStw)a9 Do basic configuration for the logging system. This function does nothing if the root logger already has handlers configured, unless the keyword argument *force* is set to ``True``. It is a convenience method intended for use by simple scripts to do one-shot configuration of the logging package. The default behaviour is to create a StreamHandler which writes to sys.stderr, set a formatter using the BASIC_FORMAT format string, and add the handler to the root logger. A number of optional keyword arguments may be specified, which can alter the default behaviour. filename Specifies that a FileHandler be created, using the specified filename, rather than a StreamHandler. filemode Specifies the mode to open the file, if filename is specified (if filemode is unspecified, it defaults to 'a'). format Use the specified format string for the handler. datefmt Use the specified date/time format. style If a format string is specified, use this to specify the type of format string (possible values '%', '{', '$', for %-formatting, :meth:`str.format` and :class:`string.Template` - defaults to '%'). level Set the root logger level to the specified level. stream Use the specified stream to initialize the StreamHandler. Note that this argument is incompatible with 'filename' - if both are present, 'stream' is ignored. handlers If specified, this should be an iterable of already created handlers, which will be added to the root handler. Any handler in the list which does not have a formatter assigned will be assigned the formatter created in this function. force If this keyword is specified as true, any existing handlers attached to the root logger are removed and closed, before carrying out the configuration as specified by the other arguments. encoding If specified together with a filename, this encoding is passed to the created FileHandler, causing it to be used when the file is opened. errors If specified together with a filename, this value is passed to the created FileHandler, causing it to be used when the file is opened in text mode. If not specified, the default value is `backslashreplace`. Note that you could specify a stream created using open(filename, mode) rather than passing the filename and mode in. However, it should be remembered that StreamHandler does not close its stream (since it may be using sys.stdout or sys.stderr), whereas FileHandler closes its stream when the handler is closed. .. versionchanged:: 3.2 Added the ``style`` parameter. .. versionchanged:: 3.3 Added the ``handlers`` parameter. A ``ValueError`` is now thrown for incompatible arguments (e.g. ``handlers`` specified together with ``filename``/``filemode``, or ``filename``/``filemode`` specified together with ``stream``, or ``handlers`` specified together with ``stream``. .. versionchanged:: 3.8 Added the ``force`` parameter. .. versionchanged:: 3.9 Added the ``encoding`` and ``errors`` parameters. forceFr<Nr>backslashreplacerrr0rkz8'stream' and 'filename' should not be specified togetherzG'stream' or 'filename' should not be specified together with 'handlers'filemoder6r7rCrrrrrrr\r5z, zUnrecognised argument(s): %s)r9poprUrrrrarHrr=r rrrrrr rrrr:)rrr<r>hrrkr;r0ZdfsrZfsrr5rr7r7r8rshF                    *rcCs(|r t|tr|tjkrtStj|S)z Return a logger with the specified name, creating it if necessary. If no name is specified, return the root logger. )rErGrUr_rr]r )r_r7r7r8r s r cO0ttjdkr ttj|g|Ri|dS)z Log a message with severity 'CRITICAL' on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format. rN)rarUrrrr`rerr7r7r8r!rcOst|g|Ri|dS)z: Don't use this function, use critical() instead. Nr|rr7r7r8r+srcOr)z Log a message with severity 'ERROR' on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format. rN)rarUrrrrr7r7r8r1rrrycOst|g|Rd|i|dS)z Log a message with severity 'ERROR' on the root logger, with exception information. If the logger has no handlers, basicConfig() is called to add a console handler with a pre-defined format. rANrz)r`rArerr7r7r8r;srcOr)z Log a message with severity 'WARNING' on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format. rN)rarUrrr(rr7r7r8r(Crr(cOs(tdtdt|g|Ri|dS)Nz8The 'warn' function is deprecated, use 'warning' insteadr?rurr7r7r8r'Msr'cOr)z Log a message with severity 'INFO' on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format. rN)rarUrrr"rr7r7r8r"Rrr"cOr)z Log a message with severity 'DEBUG' on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format. rN)rarUrrrrr7r7r8r\rrcOs2ttjdkr ttj||g|Ri|dS)z Log 'msg % args' with the integer severity 'level' on the root logger. If the logger has no handlers, call basicConfig() to add a console handler with a pre-defined format. rN)rarUrrr#)r5r`rerr7r7r8r#fsr#cCs|tj_tjdS)zB Disable all logging calls of severity 'level' and below. N)rUr]rrj)r5r7r7r8rpsrc Cst|ddD]7}z-|}|r6z z|||Wn ttfy*YnwW|n|wWqtr>YqdS)z Perform any cleanup actions in the logging system (e.g. flushing buffers). Should be called at application exit. N)reversedrNrrr*rHrOr,)Z handlerListrrr7r7r8r&ws& r&c@r) ra This handler does nothing. It's intended to be used to avoid the "No handlers could be found for logger XXX" one-off warning. This is important for library code, which may contain code to log events. If a user of the library does not configure logging, the one-off warning might be produced; to avoid this, the library developer simply needs to instantiate a NullHandler and add it to the top-level logger of the library module or package. cCrzStub.Nr7rr7r7r8rzNullHandler.handlecCrrr7rr7r7r8rrzNullHandler.emitcCs d|_dSrR)rrr7r7r8rs zNullHandler.createLockcCrQrRr7rr7r7r8rYrVzNullHandler._at_fork_reinitN)rrrrrrrrYr7r7r7r8rs   rcCsf|durtdurt||||||dSdSt|||||}td}|js+|t|d|dS)a Implementation of showwarnings which redirects to logging, which will first check to see if the file parameter is None. If a file is specified, it will delegate to the original warnings implementation of showwarning. Otherwise, it will call warnings.formatwarning and will log the resulting string to a warnings logger named "py.warnings" with level logging.WARNING. Nz py.warningsz%s)_warnings_showwarningrv formatwarningr rrrr()rcategoryrkrqr!linerrir7r7r8 _showwarnings rcCs:|rtdurtjatt_dSdStdurtt_dadSdS)z If capture is true, redirect all warnings to the logging package. If capture is False, ensure that warnings are not redirected to logging but to their original destinations. N)rrv showwarningr)Zcapturer7r7r8rs rrRr)orr=rhr^rrrrvrZcollections.abcrbstringrrZ StrFormatter__all__rv __author__Z __status__ __version__Z__date__rtr,ruryr{rr rrrr rrr2r4rrr|rDrir__code__r&rrKrrMr9r:rUZWeakSetrWr[rPobjectrrr*r)r$rrrrrrrrr rZWeakValueDictionaryrrrr r rr rFZ_defaultLastResortr+rJr%r!rTrrrRrrUr]rr rrrrr(r'r"rr#rr&atexitregisterrrrrr7r7r7r8sH           g !"#3*%4 CSU h