Ϫf UdZddlZddlmZmZddlmZddlm Z ddl m Z ddl m Z dd lmZmZdd lmZej&ej(ej*ej,ej.ej0ej2ej4ej6ej8iZee efed <d eee ffd Z e Z!eeGddZ"GddZ#y)z3 Integration with Python standard library logging. N)MappingTuple) implementer) NamedConstant) currentframe) formatEvent) ILogObserverLogEvent)LogLeveltoStdlibLogLevelMappingreturnc|i}tjD]"\}}|||<||tj|<$|S)z Reverse the above mapping, adding both the numerical keys used above and the corresponding string keys also used by python logging. @return: the reversed mapping )r items stdlibLogging getLevelName)mappinglogLevel pyLogLevels 8/usr/lib/python3/dist-packages/twisted/logger/_stdlib.py_reverseLogLevelMappingrsN G 7 = = ?C*& :B **:67C Nc deZdZdZdZdefdededdfdZ dd ed ede eeedffd Z d e ddfd Z y)STDLibLogObserverae Log observer that writes to the python standard library's C{logging} module. @note: Warning: specific logging configurations (example: network) can lead to this observer blocking. Nothing is done here to prevent that, so be sure to not to configure the standard library logging module to block when used in conjunction with this module: code within Twisted, such as twisted.web, assumes that logging does not block. @cvar defaultStackDepth: This is the default number of frames that it takes to get from L{STDLibLogObserver} through the logging module, plus one; in other words, the number of frames if you were to call a L{STDLibLogObserver} directly. This is useful to use as an offset for the C{stackDepth} parameter to C{__init__}, to add frames for other publishers. twistedname stackDepthrNc|tj||_|j|j_||_y)z @param name: logger identifier. @param stackDepth: The depth of the stack to investigate for caller metadata. N)r getLoggerlogger _findCaller findCallerr)selfrrs r__init__zSTDLibLogObserver.__init__Es/$--d3 !%!1!1 $r stackInfo stackLevelct|j}|j}d}|j|j|j f|zS)a Based on the stack depth passed to this L{STDLibLogObserver}, identify the calling function. @param stackInfo: Whether or not to construct stack information. (Currently ignored.) @param stackLevel: The number of stack frames to skip when determining the caller (currently ignored; use stackDepth on the instance). @return: Depending on Python version, either a 3-tuple of (filename, lineno, name) or a 4-tuple of that plus stack information. N)rrf_code co_filenamef_linenoco_name)r$r&r'fcoextras rr"zSTDLibLogObserver._findCallerQs>  ) XX BJJ7%??reventcT|jdtj}|jd}|d}n'|j|j|j f}t j|tj}|jj|t||y)zB Format an event and bridge it to Python logging. log_level log_failureN)exc_info) getr infotypevaluegetTracebackObjectr rINFOr!logStringifiableFromEvent)r$r1levelfailureexcInfo stdlibLevels r__call__zSTDLibLogObserver.__call__es +x}}5))M* ?G||W]]G4N4N4PQG-11%9K9KL   %;E%BWUr)Fr) __name__ __module__ __qualname____doc__defaultStackDepthstrintr%boolrr"r rBrrrr/s~$$7H % %14 %  %:;@@36@ sCd" #@( Vh V4 Vrrc8eZdZdZdeddfdZdefdZdefdZ y)r=z An object that implements C{__str__()} in order to defer the work of formatting until it's converted into a C{str}. r1rNc||_y)z) @param event: An event. N)r1)r$r1s rr%zStringifiableFromEvent.__init__ys  rc,t|jSr))r r1r$s r__str__zStringifiableFromEvent.__str__s4::&&rc6t|jdS)Nzutf-8)rHencoderOs r __bytes__z StringifiableFromEvent.__bytes__s4y((r) rCrDrErFr r%rHrPbytesrSrKrrr=r=ss2 h4 '')5)rr=)$rFloggingrtypingrrzope.interfacer constantlyrtwisted.python.compatr_formatr _interfacesr r _levelsr debugDEBUGr7r;warnWARNINGerrorERRORcriticalCRITICALr rI__annotations__rfromStdlibLogLevelMappingrr=rKrrrgs  !&$. / NNM'' MM=%% MM=(( NNM'' }-- 8!34 m);!< 45 \@V@V@VF))r