m )Ec@ sdZdklZdkZdkZdkZdkZdklZl Z l Z dfdYZ e i e hdd<dd <d Z d Zdd Zdagagad ZdZdZdZdZdZdZdddZeZdfdYZdfdYZyeWn7e j o+eZei!Z!ei"Z"ei#Z#nXdfdYZ$dfdYZ%yt&Wne j o da&nXdZ'ddZ(d fd!YZ)d"Z*yt+Wn+e j oe%da+e%dZ,nXd#fd$YZ-dk.Z.dk/Z/e.i0eyt1Wn&e j oe-a1t1i2nXdS(%s$Logging and metrics infrastructure. (sdivisionN(sutilscontextsreflectt ILogContextcB stZdZRS(sActually, this interface is just a synoym for the dictionary interface, but it serves as a key for the default information in a log. I do not inherit from Interface because the world is a cruel place. (t__name__t __module__t__doc__(((tj/home/radix/Projects/Twisted/branches/releases/twisted-core-2.5.x-2329-2/Twisted.exp/twisted/python/log.pyRs tisErroritsystemt-cO sAtiti}|i|tiht|<|||S(N( tcontexttgetRtcopytnewCtxtupdatetctxtcalltfunctargstkw(R RRRR ((RtcallWithContexts cO sy|i}Wn/tj o nd}td|nXy thd|<|||SWn)tj o ntd|nXdS(s Utility method which wraps a function in a try:/except:, logs a failure if one occurrs, and uses the system's logPrefix. s(buggy logPrefix method)RN( tloggert logPrefixtlptKeyboardInterruptterrRRRR(RRRRR((RtcallWithLogger#s c C sY|djo2td|dti|d|d|ddnt |||||dS(Ntwarningtcategorytfilenametlinenotformats2%(filename)s:%(lineno)s: %(category)s: %(warning)s( tfiletNonetmsgtmessagetreflecttqualRRRt_oldshowwarning(R!RRRR((Rt showwarning6s $cC s#tiddtdddadS(s DEPRECATED in Twisted 2.5. Support function for testing frameworks. Start keeping errors in a buffer which can be retrieved (and emptied) with flushErrors. s6log.startKeepingErrors is deprecated since Twisted 2.5Rt stackleveliiN(twarningstwarntDeprecationWarningt _keepErrors(((RtstartKeepingErrorsAs  cG s#tiddtddt|S(s DEPRECATED in Twisted 2.5. See L{TestCase.flushLoggedErrors}. Support function for testing frameworks. Return a list of errors that occurred since the last call to flushErrors(). (This will return None unless startKeepingErrors has been called.) slog.flushErrors is deprecated since Twisted 2.5. If you need to flush errors from within a unittest, use TestCase.flushLoggedErrors instead.RR&iN(R'R(R)t _flushErrorst errorTypes(R-((Rt flushErrorsPs cG srt}ga|o[xX|D]L}d}x(|D] }|i|o d}q-q-W|ot|qqWn|S(s) PRIVATE. DEPRECATED. DON'T USE. iiN(t _keptErrorstkR-terkt shouldReLogterrTtcheckR(R-R0R2R3R1((RR,ascG s'tiddtddt|dS(t DEPRECATEDs0log.ignoreErrors is deprecated since Twisted 2.5RR&iN(R'R(R)t_ignorettypes(R7((Rt ignoreErrorsrs cG s"x|D]}ti|qWdS(s) PRIVATE. DEPRECATED. DON'T USE. N(R7ttypet _ignoreErrorstappend(R7R9((RR6xscC s$tiddtddtdS(R5s0log.clearIgnores is deprecated since Twisted 2.5RR&iN(R'R(R)t _clearIgnores(((Rt clearIgnoress cC s gadS(s) PRIVATE. DEPRECATED. DON'T USE. N(R:(((RR<scK s%|djoti}nt|tiotortoZd}x5tD]-}|i |}|o d}PqKd}qKW|ot i |qqt i |nt d|d|dd|nYt|to)t dti|d|dd|n t t|d|dd|dS(s% Write a failure to the log. iitfailuretwhyRN(t_stuffRR>tFailuret isinstanceR*R:tkeepRR4trR/R;R t_whyRt Exceptiontrepr(R@RERRRCRD((RRs*   )tLoggercB stZdZdZRS(sM This represents a class which may 'own' a log. Used by subclassing. cC sdS(s Override this method to insert custom logging behavior. Its return value will be inserted in front of every line. It may be called more times than the number of output lines. RN((tself((RRs(RRRR(((RRHs t LogPublishercB s;tZdZdgZdZdZdZdZRS(s+Class for singleton log message publishing.R cC s g|_dS(N(RIt observers(RI((Rt__init__scC s(t|pt|ii|dS(sAdd a new observer. Observers are callable objects that will be called with each new log message (a dict). N(tcallabletothertAssertionErrorRIRKR;(RIRN((Rt addObserverscC s|ii|dS(sRemove an observer.N(RIRKtremoveRN(RIRN((RtremoveObserverscO stitphi}|i|||dRA(RIR!RRZRWRT((RR s"    (RRRt synchronizedRLRPRRR (((RRJs    tFileLogObservercB sStZdZeZdZdZdZdZdZ dZ dZ RS(s Log observer that writes to a file-like object. @type timeFormat: C{str} or C{NoneType} @ivar timeFormat: If not C{None}, the format string passed to strftime(). cC s|i|_|i|_dS(N(tftwriteRItflush(RIR]((RRLs cC spy||}Wn[tj o nGyd||f}Wqlyd|f}Wqhd}qhXqlXnX|S(NsDInvalid format string or unformattable object in log message: %r, %ss=UNFORMATTABLE OBJECT WRITTEN TO LOG with fmt %r, MESSAGE LOSTsJPATHOLOGICAL ERROR IN BOTH FORMAT STRING AND MESSAGE DETAILS, MESSAGE LOST(t fmtStringtcrapttextR(RIR`RaRb((Rt _safeFormatscC stio tiSntiS(s Return the current local timezone offset from UTC. @rtype: C{int} @return: The number of seconds offset from UTC. West is positive, east is negative. N(RStdaylighttaltzonettimezone(RI((RtgetTimezoneOffsets  cC s|idj o ti|iti|Sn|i }t i i ||}t |dd}t |dd}d|i|i|i|i|i||fS(s Return the given UTC value formatted as a human-readable string representing that time in the local timezone. @type when: C{int} @param when: POSIX timestamp to convert to a human-readable string. @rtype: C{str} i<s %d/%02d/%02d %02d:%02d %+03d%02dN(RIt timeFormatRRStstrftimet localtimetwhenRgttzOffsettdatetimetutcfromtimestamptintttzHourttzMintyeartmonthtdaythourtminute(RIRkRqRpRl((Rt formatTime%s   cC s!|d}|py|do<|ido,|idpdd|di}q|ido|i|d|}qdSndit t i |}|i |d }hd |d <d |idd <}|id |}ti|i|d|ti|idS(NR!RR>R?sUnhandled Errors Rt RSRRbs s[%(system)s] %(text)s (t eventDicttedmthas_keyR t getTracebackRbRIRctjointmapR"tsafe_strRwttimeStrtreplacetfmtDicttmsgStrtutiltuntilConcludesR^R_(RIRyRRbRRRz((Rtemit<s ,(cC st|idS(sStart observing log events.N(RPRIR(RI((RtstartQscC st|idS(sStop observing log events.N(RRRIR(RI((RtstopUs( RRRRRhRLRcRgRwRRR(((RR\s      tStdioOnnaStickcB stZdZdZdZdZdZddZdZdZ dZ dZ e Z e Z e Ze Zd Zd ZRS( s$Class that pretends to be stout/err.itwbs cC s||_d|_dS(Nt(RRItbuf(RIR((RRLbs cC sdS(N((RI((RtclosefscC sdS(Ni((RI((RtfilenoiscC sdS(N((RI((RR_lscC stddS(Nscan't read from the log!(tIOError(RI((RtreadoscC s^|i|id}|d|_|dd!}x'|D]}t|ddd|iq7WdS(Ns iitprintediR( RIRtdatatsplittdtmessagesR!R R(RIRRRR!((RR^ws   cC s.x'|D]}t|ddd|iqWdS(NRiR(tlinestlineR RIR(RIRR((Rt writelines~s(RRRtclosedt softspacetmodetnameRLRRR_Rtreadlinet readlinestseekttellR^R(((RRZs       cO s#t|}t|i||dS(s,Initialize logging to a specified file. N(R\RtflotstartLoggingWithObserverRtaR(RRRR((Rt startLoggings icC smtptiatt_ntotidant|td|ot t _ t t _ndS(sInitialize logging to a specified observer. If setStdout is true (defaults to yes), also redirect sys.stdout and sys.stderr to the specified file. s Log opened.N(R$R'R%tdefaultObserverRRRPtobserverR t setStdouttlogfiletsyststdouttlogerrtstderr(RR((RRs       tNullFilecB s2tZdZdZdZdZdZRS(NicC sdS(N((RI((RRscC sdS(N((RItbytes((RR^scC sdS(N((RI((RR_scC sdS(N((RI((RRs(RRRRR^R_R(((RRs    cC s tadS(sThrow away all logs. N(RR(((Rt discardLogsstDefaultObservercB s)tZdZdZdZdZRS(sDefault observer. Will ignore all non-error messages and send error messages to sys.stderr. Will be removed when startLogging() is called for the first time. cC s|do}|ido|di}n9dig}|dD]}|t|qD~d}ti i |ti i ndS(NRR>RxR!s ( RyR{R|RbR}t_[1]tmtstrRRR^R_(RIRyRbRR((Rt_emits  8cC st|idS(N(RPRIR(RI((RRscC st|idS(N(RRRIR(RI((RRs(RRRRRR(((RRs  (3Rt __future__tdivisionRRSR'Rmttwisted.pythonRRR"Rt setDefaultRRRR%R*R/R:R+R.R,R8R6R=R<RtdeferrRHRJttheLogPublishert NameErrorRPRRR R\RR$RRRRRRRt threadableR>t synchronizeRR(%RRRR,RmRHRR%RRRRRR=R R+R\R>RRR'R.RJR8R<R6RRRRRRR"RRSRRRP((Rt?sp                 6   e)