m &UIc@sTdZdkZdkZdkZdkZdkZdkZdkZy dkZWne j o dZnXydk Z dk Z Wne j o dZ nXdZ dZdZdZeedodeiedfZn9eiedd d gjoed d ZneZeiieZd Zeed o eiZneiZdZdZeZdZdZeZ dZ!dZ"dZ#hed<ed<ed<e!d<e"d<e#d<de<de<de<de<de!<de"<de#d;Z?d<Z@dd=ZAd>ZBeBZCd?ZDd@ZEdAZFeFZGdBZHdCZIdDZJdEZKdFZLydkMZMeMiNeLWn+e j oeiOdGZPePe_OnXdS(Hsj Logging package for Python. Based on PEP 282 and comments thereto in comp.lang.python, and influenced by Apache's log4j system. Should work under Python versions >= 1.5.2, except that source line information is not available unless 'sys._getframe()' is. Copyright (C) 2001-2004 Vinay Sajip. All Rights Reserved. To use, simply 'import logging' and log away! Ns&Vinay Sajip tbetas0.4.9.7s07 October 2005tfrozenslogging%s__init__%sis.pycs.pyos.pycCs%y tWntiiiSnXdS(s5Return the frame object for the caller's stack frame.N(t Exceptiontsyst exc_tracebackttb_frametf_back(((t-/data/zmath/lib/python2.4/logging/__init__.pyt currentframe@s  t _getframeii2i(iii itCRITICALtERRORtWARNINGtINFOtDEBUGtNOTSETtWARNcCsti|d|S(s Return the textual 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. Otherwise, the string "Level %s" % level is returned. sLevel %sN(t _levelNamestgettlevel(R((Rt getLevelNames cCs.tz|t|<|t|(R$R#R,R-R7R%(R$((Rt__str__scCsttdpt|i}n_|i}t|titifjo6yt|i}Wqtj o|i}qXn|i o||i }n|S(s Return the message for this LogRecord. Return the message for this LogRecord after merging any user-supplied arguments with the message. t UnicodeTypeN( RAR)tstrR$R%R(REt StringTypet UnicodeErrorR&(R$R%((Rt getMessages  (t__name__t __module__t__doc__RCRDRI(((RRs  1 cCs2tdddddfd}|ii||S(s 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. tiN(RR5trvt__dict__tupdatetdict(RQRN((Rt makeLogRecordst FormattercBsDtZdZeiZeedZedZdZ dZ RS(s Formatter instances are used to convert a LogRecord to text. Formatters need to know how a LogRecord is constructed. They are responsible for converting a LogRecord to (usually) a string which can be interpreted by either a human or an external system. The base Formatter allows a formatting string to be specified. If none is supplied, the default value of "%s(message)\n" is used. The Formatter can be initialized with a format string which makes use of knowledge of the LogRecord attributes - e.g. the default value mentioned above makes use of the fact that the user's message and arguments are pre- formatted into a LogRecord's message attribute. Currently, the useful attributes in a LogRecord are described by: %(name)s Name of the logger (logging channel) %(levelno)s Numeric logging level for the message (DEBUG, INFO, WARNING, ERROR, CRITICAL) %(levelname)s Text logging level for the message ("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL") %(pathname)s Full pathname of the source file where the logging call was issued (if available) %(filename)s Filename portion of pathname %(module)s Module (name portion of filename) %(lineno)d Source line number where the logging call was issued (if available) %(created)f Time when the LogRecord was created (time.time() return value) %(asctime)s Textual time when the LogRecord was created %(msecs)d Millisecond portion of the creation time %(relativeCreated)d Time in milliseconds when the LogRecord was created, relative to the time the logging module was loaded (typically at application startup time) %(thread)d Thread ID (if available) %(threadName)s Thread name (if available) %(process)d Process ID (if available) %(message)s The result of record.getMessage(), computed just as the record is emitted cCs*|o ||_n d|_||_dS(s8 Initialize the formatter with specified format strings. Initialize the formatter either with the specified format string, or a default as described above. Allow for specialized date formatting with the optional datefmt argument (if omitted, you get the ISO8601 format). s %(message)sN(tfmtR$t_fmttdatefmt(R$RTRV((RRCQs   cCsX|i|i}|oti||}n&tid|}d||i f}|S(s Return the creation time of the specified LogRecord as formatted text. This method should be called from format() by a formatter which wants to make use of a formatted time. This method can be overridden in formatters to provide for any specific requirement, but the basic behaviour is as follows: if datefmt (a string) is specified, it is used with time.strftime() to format the creation time of the record. Otherwise, the ISO8601 format is used. The resulting string is returned. This function uses a user-configurable function to convert the creation time to a tuple. By default, time.localtime() is used; to change this for a particular formatter instance, set the 'converter' attribute to a function with the same signature as time.localtime() or time.gmtime(). To change it for all formatters, for example if you want all logging times to be shown in GMT, set the 'converter' attribute in the Formatter class. s%Y-%m-%d %H:%M:%Ss%s,%03dN( R$t convertertrecordR8R"RVR!tstrftimetsttR:(R$RXRVRZR[R"((Rt formatTime_scCsjti}ti|d|d|dd||i}|i |ddjo|d }n|S(s Format and return the specified exception information as a string. This default implementation just uses traceback.print_exception() iiiis N( t cStringIOtStringIOtsiot tracebacktprint_exceptionteiR5tgetvalueRZtclose(R$RbRZR_((RtformatExceptionys %  cCs|i|_ti|iddjo|i||i|_ n|i|i }|i o'|i p|i|i |_ qn|i o0|ddjo|d}n||i }n|S(s[ Format the specified record as text. The record's attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string contains "%(asctime)", formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message. s %(asctime)iis N(RXRItmessagetstringtfindR$RUR\RVtasctimeRORZR4R6Re(R$RXRZ((Rtformats    ( RJRKRLR!t localtimeRWR5RCR\ReRj(((RRS&s '   tBufferingFormattercBs5tZdZedZdZdZdZRS(sB A formatter suitable for formatting a number of records. cCs!|o ||_n t|_dS(sm Optionally specify a formatter which will be used to format each individual record. N(tlinefmtR$t_defaultFormatter(R$Rm((RRCs cCsdS(sE Return the header string for the specified records. RMN((R$trecords((Rt formatHeaderscCsdS(sE Return the footer string for the specified records. RMN((R$Ro((Rt formatFooterscCsnd}t|djoQ||i|}x$|D]}||ii|}q3W||i|}n|S(sQ Format the specified records and return the result as a string. RMiN( RNR'RoR$RpRXRmRjRq(R$RoRNRX((RRjs(RJRKRLR5RCRpRqRj(((RRls   tFiltercBs#tZdZddZdZRS(s Filter instances are used to perform arbitrary filtering of LogRecords. Loggers and Handlers can optionally use Filter instances to filter records as desired. The base filter class only allows events which are below a certain point in the logger hierarchy. For example, a filter initialized with "A.B" will allow events logged by loggers "A.B", "A.B.C", "A.B.C.D", "A.B.D" etc. but not "A.BB", "B.A.B" etc. If initialized with the empty string, all events are passed. RMcCs||_t||_dS(s Initialize a filter. Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event. N(R#R$R'tnlen(R$R#((RRCs cCsw|idjodSnL|i|ijodSn1ti|i|id|idjodSn|i|idjS(s Determine if the specified record is to be logged. Is the specified record to be logged? Returns 0 for no, nonzero for yes. If deemed appropriate, the record may be modified in-place. iit.N(R$RsR#RXRgRh(R$RX((Rtfilters((RJRKRLRCRu(((RRrs  tFilterercBs2tZdZdZdZdZdZRS(s[ A base class for loggers and handlers which allows them to share common code. cCs g|_dS(sE Initialize the list of filters to be an empty list. N(R$tfilters(R$((RRCscCs(||ijo|ii|ndS(s; Add the specified filter to this handler. N(RuR$Rwtappend(R$Ru((Rt addFilterscCs(||ijo|ii|ndS(s@ Remove the specified filter from this handler. N(RuR$Rwtremove(R$Ru((Rt removeFilter scCs9d}x,|iD]!}|i|p d}PqqW|S(s Determine if a record is loggable by consulting all the filters. The default is to allow the record to be logged; any filter can veto this and the record is then dropped. Returns a zero value if a record is to be dropped, else non-zero. iiN(RNR$RwtfRuRX(R$RXRNR|((RRus  (RJRKRLRCRyR{Ru(((RRvs    tHandlercBs}tZdZedZdZdZdZdZdZ dZ dZ d Z d Z d Zd ZRS( sq Handler instances dispatch logging events to specific destinations. The base handler class. Acts as a placeholder which defines the Handler interface. Handlers can optionally use Formatter instances to format records as desired. By default, no formatter is specified; in this case, the 'raw' message as determined by record.message is logged. cCs]ti|||_d|_tzdt|s    cCsd}tz|ii|oj|i|}t|toI|}t |}||_ ||i|<|i |||i |qn0t |}||_ ||i|<|i |WdtX|S(s 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. N(R5RNRR$RRR#t isinstanceRtphRtmanagert_fixupChildrent _fixupParentsR(R$R#RNR((Rt getLoggerGs(        cCs|i}ti|d}d}x|djo| o|| }|i i |pt ||i |qXqWdS(s Perform any cleanup actions in the logging system (e.g. flushing buffers). Should be called at application exit. N(RthRRdR(R((Rtshutdown)s cCsz tWd||XdS(N(Rtold_exittstatus(RR((Rtexithook@s (QRLRR.R)R!RgR]R`Rt ImportErrorR5RRt __author__t __status__t __version__t__date__RAtsept__file__RtlowerR/RRR R;RR tFATALR R RR RRRRRRRRRRRRSRnRlRrRvRRR}RRRRRRRRRRRRRRRRRRRRRRRRRtatexittregistertexitR(BR]RRR RRvRRR}RRRRSRRRrR RRRRRRR R)RRRRRR RgRnR;RRRRRRRRRRRRRRlRRRRRRR`RRRRRRRR!RR.RR((Rt?s?          {   U  *%,2  U    6