o [dh9 @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 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)levelresultr8'/usr/lib/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) _acquireLockr3r5 _releaseLock)r6 levelNamer8r8r9rs  r _getframecCs tdS)N)sysr=r8r8r8r9s r@cCs(zttytdjjYSw)z5Return the frame object for the caller's stack frame.) Exceptionr?exc_infotb_framef_backr8r8r8r9 currentframes  rFcCsLt|tr |}|St||kr|tvrtd|t|}|Std|f)NzUnknown level: %rz*Level not an integer or a valid string: %r) isinstanceintstrr5 ValueError TypeError)r6rvr8r8r9 _checkLevels   rMcCtrtdSdS)z Acquire the module-level lock for serializing access to shared data. This should be released with _releaseLock(). N)_lockacquirer8r8r8r9r:s r:cCrN)zK Release the module-level lock acquired by calling _acquireLock(). N)rOreleaser8r8r8r9r;s r;register_at_forkcCdSNr8instancer8r8r9_register_at_fork_reinit_lockrWcCs&tz t|WtdStwrT)r:_at_fork_reinit_lock_weaksetaddr;rUr8r8r9rWs cCstD]}|qtdSrT)rY_at_fork_reinitrOhandlerr8r8r9!_after_at_fork_child_reinit_lockss  r^)beforeafter_in_childafter_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 moduleNig MainProcessmultiprocessinggetpid)1timenamemsglenrG collectionsabcMappingargsr levelnamelevelnopathnameospathbasenamefilenamesplitextmodulerKrJAttributeErrorrCexc_text stack_infolinenofuncNamecreatedrHmsecs _startTimerelativeCreated logThreads threading get_identthreadcurrent_thread threadNamelogMultiprocessing processNamer?modulesr4current_processrB logProcesseshasattrreprocess) selfrgr6rprzrhrmrCfuncsinfokwargsctmpr8r8r9__init__sX"      zLogRecord.__init__cCsd|j|j|j|j|jfS)Nz!)rgrorprzrhrr8r8r9__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. )rIrhrm)rrhr8r8r9 getMessagegs  zLogRecord.getMessageNN)__name__ __module__ __qualname____doc__rrrr8r8r8r9rs  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)factoryr8r8r9r*xsr*cCtS)zH Return the factory to be used when instantiating a log record. rr8r8r8r9r)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. Nrr8)r__dict__update)dictrLr8r8r9r$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|_||_dSrT)default_format_fmt _defaults)rfmtrr8r8r9rs  zPercentStyle.__init__cCs|j|jdkS)Nrrfindasctime_searchrr8r8r9usesTimeszPercentStyle.usesTimecCs*|j|jstd|j|jdfdS)z>Validate the input format, ensure it matches the correct stylez"Invalid format '%s' for '%s' stylerN)validation_patternsearchrrJrrr8r8r9validateszPercentStyle.validatecCs&|j}r ||jB}n|j}|j|SrT)rrrrrecordrvaluesr8r8r9_formats   zPercentStyle._formatc Cs2z||WSty}ztd|d}~ww)Nz(Formatting field not found in record: %s)rKeyErrorrJ)rrer8r8r9formats   zPercentStyle.format)rrrrasctime_formatrrecompileIrrrrrrr8r8r8r9rs 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|SNr8)rrrrrr8r8r9r  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. )rrPr1rQ)rrrLr8r8r9handles   zHandler.handlecC ||_dS)z5 Set the formatter for this handler. N)r"rr8r8r9 setFormatterrzHandler.setFormattercCr)z Ensure all logging output has been flushed. This version does nothing and is intended to be implemented by subclasses. Nr8rr8r8r9flushsz 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)r:r#r!r(r;rr8r8r9rs    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?stderrrCwriterrrDrqrrdirnamef_code co_filename__path__rE print_stackrtrzrhrmRecursionErrorrBOSError)rrtvrframer8r8r9 handleErrorsN       zHandler.handleErrorcCst|j}d|jj|fS)Nz <%s (%s)>)rr6rrr%r8r8r9rs zHandler.__repr__N)rrrrrrr'r)propertyrgr$r[rPrQr.rr1r2r4r5rrDrr8r8r8r9r _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?r8streamrrFr8r8r9r*s  zStreamHandler.__init__cCsZ|z#|jrt|jdr!|jW|dSW|dSW|dS|w)z% Flushes the stream. r5N)rPrFrr5rQrr8r8r9r55s   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)rrFr9 terminatorr5r?rBrD)rrrhrFr8r8r9r1@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)rFrPr5rQ)rrFr7r8r8r9 setStreamVs   zStreamHandler.setStreamcCs>t|j}t|jdd}t|}|r|d7}d|jj||fS)Nrgr z <%s %s(%s)>)rr6getattrrFrIrr)rr6rgr8r8r9rjs zStreamHandler.__repr__rT) rrrrrHrr5r1rIrr8r8r8r9r!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)rqfspathrrabspath baseFilenamemodeencodingr text_encodingerrorsdelayopen _builtin_openr rrFr_open)rrtrQrRrUrTr8r8r9rxs    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)rPrFr5rrrrQrGr8r8r9rs&    zFileHandler.closecCs|j}||j|j|j|jdS)zx Open the current base file with the (original) mode and encoding. Return the resulting stream. rRrT)rWrPrQrRrT)r open_funcr8r8r9rXs 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)rFrQr#rXrr1rr8r8r9r1s  zFileHandler.emitcCst|j}d|jj|j|fSNz <%s %s (%s)>)rr6rrrPr%r8r8r9rs zFileHandler.__repr__)rLNFN) rrrrrrrXr1rr8r8r8r9r 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 rr%r8r8r9rz_StderrHandler.__init__cCstjSrT)r?r8rr8r8r9rFz_StderrHandler.streamN)rrrrrrrErFr8r8r8r9r]s  r]c@ 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 loggerMapraloggerr8r8r9rr/zPlaceHolder.__init__cCs||jvr d|j|<dSdS)zJ Add the specified logger as a child of this placeholder. Nrbrdr8r8r9rs zPlaceHolder.appendN)rrrrrrr8r8r8r9ra racCs(|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 issubclassrKr _loggerClass)klassr8r8r9r%s  r%cCr)zB Return the class to be used when instantiating a logger. )rir8r8r8r9r!r r!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)rrootnoder8r8r9rs  zManager.__init__cCr&rT)_disablerr8r8r9rr_zManager.disablecCst||_dSrT)rMrrrvaluer8r8r9rscCsd}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) rGrIrKr:rnrarorimanager_fixupChildren _fixupParentsr;)rrgrLphr8r8r9r #s2         zManager.getLoggercCs*|tkrt|tstd|j||_dS)zY Set the class to be used when instantiating a logger with this Manager. rgN)rrhrKrro)rrjr8r8r9r%Es   zManager.setLoggerClasscCr3)zg Set the factory to be used when instantiating a log record with this Manager. N)rp)rrr8r8r9r*Os zManager.setLogRecordFactorycCs|j}|d}d}|dkrK|sK|d|}||jvr#t||j|<n|j|}t|tr0|}n t|ts7J|||dd|d}|dkrK|r|sP|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. rNrrb) rgrfindrnrarGrrrlparent)rrergirLsubstrobjr8r8r9rwVs"          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)rgrircrrz)rrxrergnamelencr8r8r9rvnszManager._fixupChildrencCs@t|jD] }t|tr|jq|jjtdS)zj Clear the cache for all loggers in loggerDict Called when level changes are made N) r:rnrrGr_cacheclearrlr;rloggerr8r8r9 _clear_cache{s    zManager._clear_cacheN)rrrrrrErsetterr r%r*rwrvrr8r8r8r9rk s  "  rkc@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) rrrgrMr6rz propagaterdisabledr)rrgr6r8r8r9rs   zLogger.__init__cCst||_|jdS)zW Set the logging level of this logger. level must be an int or a str. N)rMr6rurr%r8r8r9r.s 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_logrrhrmrr8r8r9r z Logger.debugcOr)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)rr rrr8r8r9r"rz Logger.infocOr)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)rrrrr8r8r9r(rzLogger.warningcO*tdtd|j|g|Ri|dSNz6The 'warn' method is deprecated, use 'warning' insteadrAwarningsr'DeprecationWarningr(rr8r8r9r'z Logger.warncOr)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)rrrrr8r8r9rrz Logger.errorTrCcOs |j|g|Rd|i|dS)zU Convenience method for logging an ERROR with exception information. rCNrrrhrCrmrr8r8r9rs zLogger.exceptioncOr)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)rrrrr8r8r9rrzLogger.criticalcOs|j|g|Ri|dS)z@ Don't use this method, use critical() instead. Nrrr8r8r9rsz 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)rGrHr,rKrrrr6rhrmrr8r8r9r#s  z Logger.logFrbc 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. Nrb)(unknown file)r(unknown function)Nr;zStack (most recent call last): r6rr)rFrErr;rqrrnormcaser<_srcfilerrr9rr>rrf_linenoco_name) rry stacklevelrorig_frLcortrrr8r8r9 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) rrgr6fnlnorhrmrCrextrarrLkeyr8r8r9 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)rrr) rrrJrG BaseExceptiontype __traceback__tupler?rCrrgr2) rr6rhrmrCrryrrrrrrr8r8r9r@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)rr callHandlersrr8r8r9r2Zsz Logger.handlecCs>tz||jvr|j|WtdSWtdStw)z; Add the specified handler to this logger. N)r:rrr;rhdlrr8r8r9 addHandlerd  zLogger.addHandlercCs>tz||jvr|j|WtdSWtdStw)z@ Remove the specified handler from this logger. N)r:rrr;rr8r8r9 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)rrrz)rrrLr8r8r9 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. rrbNz+No handlers could be found for logger "%s" T)rror6r2rrzr+r,rurmr?r8r9rg)rrrfoundrr8r8r9rs0        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. )r6rzrrr8r8r9getEffectiveLevelszLogger.getEffectiveLevelc Cs|jrdSz|j|WStyCtz)|jj|kr$d}|j|<n||k}|j|<Wt|YSWt|YStww); Is this logger enabled for level 'level'? F)rrrr:rurrr;)rr6 is_enabledr8r8r9rs$    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)rlrrgrur )rsuffixr8r8r9getChilds  zLogger.getChildcCs t|}d|jj|j|fSr\)rrrrrgr%r8r8r9rs zLogger.__repr__cCs,t|j|urddl}|dt|jffS)Nrzlogger cannot be pickled)r rgpickle PicklingError)rrr8r8r9 __reduce__s  zLogger.__reduce__)Frb)NNN)NNFrb)rrrrrrr.rr"r(r'rrrrr#rrrr2rrrrrrrrrr8r8r8r9rs:        %      rc@r`) 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". rlN)rrr%r8r8r9rszRootLogger.__init__cCstdfSr)r rr8r8r9rszRootLogger.__reduce__N)rrrrrrr8r8r8r9rrfrc@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)rr)rrrr8r8r9r 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)rrhrr8r8r9rs zLoggerAdapter.processcO|jt|g|Ri|dS)zA Delegate a debug call to the underlying logger. N)r#rrr8r8r9r'zLoggerAdapter.debugcOr)zA Delegate an info call to the underlying logger. N)r#r rr8r8r9r"-rzLoggerAdapter.infocOr)zC Delegate a warning call to the underlying logger. N)r#rrr8r8r9r(3rzLoggerAdapter.warningcOrrrrr8r8r9r'9rzLoggerAdapter.warncOr)zB Delegate an error call to the underlying logger. Nr#rrr8r8r9r>rzLoggerAdapter.errorTrcOs"|jt|g|Rd|i|dS)zF Delegate an exception call to the underlying logger. rCNrrr8r8r9rDs"zLoggerAdapter.exceptioncOr)zD Delegate a critical call to the underlying logger. N)r#rrr8r8r9rJrzLoggerAdapter.criticalcOs>||r|||\}}|jj||g|Ri|dSdS)z Delegate a log call to the underlying logger, after adding contextual information from this adapter instance. N)rrrr#rr8r8r9r#Ps  zLoggerAdapter.logcCr)r)rrr%r8r8r9rYs zLoggerAdapter.isEnabledForcCs|j|dS)zC Set the specified level on the underlying logger. N)rr.r%r8r8r9r._r^zLoggerAdapter.setLevelcCr)zD Get the effective level for the underlying logger. )rrrr8r8r9rerzLoggerAdapter.getEffectiveLevelcCr)z@ See if the underlying logger has any handlers. )rrrr8r8r9rkrzLoggerAdapter.hasHandlersFcCs|jj||||||dS)zX Low-level log implementation, proxied to allow nested logger adapters. )rCrry)rr)rr6rhrmrCrryr8r8r9rqszLoggerAdapter._logcC|jjSrTrrurr8r8r9ru~zLoggerAdapter.managercCs ||j_dSrTrrsr8r8r9rus cCrrT)rrgrr8r8r9rgrzLoggerAdapter.namecCs&|j}t|}d|jj|j|fSr\)rrrrrrg)rrr6r8r8r9rs zLoggerAdapter.__repr__rT)NNF)rrrrrrrr"r(r'rrrr#rr.rrrrErurrgrr8r8r8r9rs0       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. forceFrRNrTbackslashreplacerrrFrtz8'stream' and 'filename' should not be specified togetherzG'stream' or 'filename' should not be specified together with 'handlers'filemoderLrMrYrrrrrrrbr6z, zUnrecognised argument(s): %s)r:poprlrrrrirJrrSr rrrrrr"r4rr.r;)rrrRrThrrtrQrFdfsrfsrr6rr8r8r9rshF                    *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. )rGrIrlrgrrur )rgr8r8r9r 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)rirlrrrrhrmrr8r8r9r!rcOst|g|Ri|dS)z: Don't use this function, use critical() instead. Nrrr8r8r9r+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)rirlrrrrr8r8r9r1rrrcOst|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. rCNr)rhrCrmrr8r8r9r;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)rirlrrr(rr8r8r9r(Crr(cOs(tdtdt|g|Ri|dS)Nz8The 'warn' function is deprecated, use 'warning' insteadrArrr8r8r9r'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)rirlrrr"rr8r8r9r"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)rirlrrrrr8r8r9r\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)rirlrrr#)r6rhrmrr8r8r9r#fsr#cCs|tj_tjdS)zB Disable all logging calls of severity 'level' and below. N)rlrurr)r6r8r8r9rpsrc 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)reversedrPr5rr@rJrQr,) handlerListrrr8r8r9r&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.Nr8rr8r8r9r2zNullHandler.handlecCrrr8rr8r8r9r1rzNullHandler.emitcCs d|_dSrT)r+rr8r8r9r$s zNullHandler.createLockcCrSrTr8rr8r8r9r[rXzNullHandler._at_fork_reinitN)rrrrr2r1r$r[r8r8r8r9rs   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_showwarningr formatwarningr rrrr()rcategoryrtrzr7linerrr8r8r9 _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)rr showwarningr)capturer8r8r9rs rrTr)orr?rqrfrrrrrcollections.abcrjstringrr StrFormatter__all__r __author__ __status__ __version____date__r~r,rrrrr rrrr rrr3r5rrrrFrrr__code__r<rrMr*rOr:r;rWWeakSetrYr^rRobjectrrr*r)r$rrrrrrrrr rWeakValueDictionaryr(rrr r rr r]_defaultLastResortr+rar%r!rkrrrirrlrurr rrrrr(r'r"rr#rr&atexitregisterrrrrr8r8r8r9sH           g !"#3*%4 CSU h