- CcsXdZdkZdkZdkZdkZdkZdkZy dkZ!dkZWn"e j o#e ZnX%dZ &dZ 'dZ (dZ2eiedddgjo3ed d Zn 5eZ6eiieZ<eed  o =e ZnBeiZHd ZTd ZUeZVd ZWdZXeZYdZZdZ[dZ]hde<de<de<de<de<de<ed<ed<ed<ed<ed<ed<edd=Z?e?Z@d>ZAd?ZBd@ZCdAZDdS(Bsj 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-2002 Vinay Sajip. All Rights Reserved. To use, simply 'import logging' and log away! Ns&Vinay Sajip sbetas0.4.8.1s 26 June 2003is.pycs.pyos.pys _getframeii2i(iii isCRITICALsERRORsWARNINGsINFOsDEBUGsNOTSETsWARNcs!mvwti|d|SdS(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. Otherwise, the string "Level %s" % level is returned. sLevel %sN(s _levelNamessgetslevel(slevel((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys getLevelNamems csFy~tz|t|<|t|(sselfsnameslevelnospathnameslinenosmsg(sself((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys__str__scsttd ot|i}n?yt|i}Wn"tj o|i}nX|io||i}n|SdS(s Return the message for this LogRecord. Return the message for this LogRecord after merging any user-supplied arguments with the message. s UnicodeTypeN(shasattrstypessstrsselfsmsgs UnicodeErrorsargs(sselfsmsg((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys getMessages (s__name__s __module__s__doc__s__init__s__str__s getMessage(((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys LogRecords   csEtttdddft}|ii||SdS(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. siN(s LogRecordsNonesrvs__dict__supdatesdict(sdictsrv((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys makeLogRecords!s FormattercsYtZdZ!#eiZ%eedZ3edZMdZ ]dZ RS(sP 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) %(process)d Process ID (if available) %(message)s The result of record.getMessage(), computed just as the record is emitted cs<%,-|o.||_n 0d|_1||_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(sfmtsselfs_fmtsdatefmt(sselfsfmtsdatefmt((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys__init__%s   cst3DE|i|i}F|oGti||}n,Itid|}Jd||i f}K|SdS(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( sselfs convertersrecordscreatedsctsdatefmtstimesstrftimessstsmsecs(sselfsrecordsdatefmtssstsct((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys formatTime3s csMSTdk}Uti}V|i|d|d|dt|W|i}X|i Y|ddjoZ|d }n[|SdS(s Format and return the specified exception information as a string. This default implementation just uses traceback.print_exception() Niiiis ( s tracebacks cStringIOsStringIOssiosprint_exceptionseisNonesgetvaluesssclose(sselfseis tracebackssioss((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pysformatExceptionMs ( cs]ij|i|_kti|iddjol|i||i|_ nm|i|i }n|i oBo|ddjop|d}nq||i |i }nr|SdS(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(srecords getMessagesmessagesstringsfindsselfs_fmts formatTimesdatefmtsasctimes__dict__sssexc_infosformatException(sselfsrecordss((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pysformat]s  ( s__name__s __module__s__doc__stimes localtimes convertersNones__init__s formatTimesformatExceptionsformat(((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys Formatters &  sBufferingFormattercsGytZdZ|}edZdZdZdZRS(sB A formatter suitable for formatting a number of records. cs0}|o||_n t|_dS(sm Optionally specify a formatter which will be used to format each individual record. N(slinefmtsselfs_defaultFormatter(sselfslinefmt((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys__init__}s csdSdS(sE Return the header string for the specified records. sN((sselfsrecords((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys formatHeaderscsdSdS(sE Return the footer string for the specified records. sN((sselfsrecords((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys formatFooterscsd}t|djo`||i|}x*|D]}||ii|}qEW||i|}n|SdS(sQ Format the specified records and return the result as a string. siN( srvslensrecordssselfs formatHeadersrecordslinefmtsformats formatFooter(sselfsrecordssrvsrecord((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pysformats  (s__name__s __module__s__doc__sNones__init__s formatHeaders formatFootersformat(((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pysBufferingFormatterys   sFiltercs/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. scs(||_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(snamesselfslensnlen(sselfsname((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys__init__s cs|idjo dSnX|i|ijo dSn7ti|i|id|idjo dSn|i|idjSdS(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. iis.N(sselfsnlensnamesrecordsstringsfind(sselfsrecord((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pysfilters  + (s__name__s __module__s__doc__s__init__sfilter(((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pysFilters  sFilterercsDtZdZdZdZdZdZRS(s[ A base class for loggers and handlers which allows them to share common code. csg|_dS(sE Initialize the list of filters to be an empty list. N(sselfsfilters(sself((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys__init__scs5||ij o|ii|ndS(s; Add the specified filter to this handler. N(sfiltersselfsfilterssappend(sselfsfilter((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys addFilterscs4||ijo|ii|ndS(s@ Remove the specified filter from this handler. N(sfiltersselfsfilterssremove(sselfsfilter((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys removeFilterscsYd}x9|iD]+}|i| od}PnqW|SdS(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(srvsselfsfilterssfsfiltersrecord(sselfsrecordsrvsf((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pysfilters    (s__name__s __module__s__doc__s__init__s addFilters removeFiltersfilter(((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pysFilterers    sHandlercstZdZedZdZdZdZ&dZ,dZ 9dZ CdZ Ud Z [d Z dd Zmd 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. csnti|||_t|_t z dt|ti|t||||_||_dS(sO Open the specified file and use it as the stream for logging. N(s StreamHandlers__init__sselfsopensfilenamesmodes baseFilename(sselfsfilenamesmode((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys__init__s cs|iidS(s$ Closes the stream. N(sselfsstreamsclose(sself((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pyscloses(s__name__s __module__s__doc__s__init__sclose(((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys FileHandlerss PlaceHoldercs,tZdZdZdZRS(s PlaceHolder instances are used in the Manager logger hierarchy to take the place of nodes for which no loggers have been defined [FIXME add example]. cs|g|_dS(sY Initialize with the specified logger being a child of this placeholder. N(saloggersselfsloggers(sselfsalogger((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys__init__scs4||ijo|ii|ndS(sJ Add the specified logger as a child of this placeholder. N(saloggersselfsloggerssappend(sselfsalogger((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pysappends(s__name__s __module__s__doc__s__init__sappend(((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys PlaceHolders csU|tjo/t|t otd|inn|adS(s 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__() s(logger not derived from logging.Logger: N(sklasssLoggers issubclasss TypeErrors__name__s _loggerClass(sklass((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pyssetLoggerClasss sManagercsDtZdZdZdZdZ.dZRS(st There is [under normal circumstances] just one Manager instance, which holds the hierarchy of loggers. cs:||_d|_d|_h|_dS(sT Initialize the manager with the root node of the logger hierarchy. iN(srootnodesselfsrootsdisablesemittedNoHandlerWarnings loggerDict(sselfsrootnode((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys__init__s    cst}tz|ii|o|i|}t|to[|}t |} ||_  ||i|< |i || |i |nn<t |}||_ ||i|<|i |WdtX|SdS(s Get a logger with the specified name (channel name), creating it if it doesn't yet exist. 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(sNonesrvs _acquireLocksselfs loggerDictshas_keysnames isinstances PlaceHoldersphs _loggerClasssmanagers_fixupChildrens _fixupParentss _releaseLock(sselfsnamesrvsph((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys getLoggers(       cs<|i}ti|d}t}x|djo| o|| } |i i | o!t ||i |iN(s_srcfilesselfs findCallersfnslnosexc_infossyss makeRecordsnameslevelsmsgsargssrecordshandle(sselfslevelsmsgsargssexc_infosrecordslnosfn((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys_logs  'cs<|i o |i|o|i|ndS(s 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(sselfsdisabledsfiltersrecords callHandlers(sselfsrecord((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pyshandlescs5||ij o|ii|ndS(s; Add the specified handler to this logger. N(shdlrsselfshandlerssappend(sselfshdlr((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys addHandlerscs4||ijo|ii|ndS(s@ Remove the specified handler from this logger. N(shdlrsselfshandlerssremove(sselfshdlr((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys removeHandlerscs|}d} x |o| xK|iD ]=} |d} |i|ijo |i|nq5W|i o t }n |i }qW|djo |i i o-tiid|id|i _ ndS(s 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. iis+No handlers could be found for logger "%s" N(sselfscsfoundshandlersshdlrsrecordslevelnoslevelshandles propagatesNonesparentsmanagersemittedNoHandlerWarningssyssstderrswritesname(sselfsrecordsfoundscshdlr((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys callHandlerss        csV|}x6|o+ |io!|iSn"|i}qW#tSdS(s 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. N(sselfsloggerslevelsparentsNOTSET(sselfslogger((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pysgetEffectiveLevels   cs>%()|ii|jo *dSn+||ijSdS(s; Is this logger enabled for level 'level'? iN(sselfsmanagersdisableslevelsgetEffectiveLevel(sselfslevel((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys isEnabledFor%s (s__name__s __module__s__doc__sNOTSETs__init__ssetLevelsdebugsinfoswarningswarnserrors exceptionscriticalsfatalslogs findCallers makeRecordsNones_logshandles addHandlers removeHandlers callHandlerssgetEffectiveLevels isEnabledFor(((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pysLogger<s*               s RootLoggercs -tZdZ23dZRS(s 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. cs 367ti|d|dS(s= Initialize the logger with the name "root". srootN(sLoggers__init__sselfslevel(sselfslevel((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys__init__3s(s__name__s __module__s__doc__s__init__(((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys RootLogger-ss"%(levelname)s:%(name)s:%(message)scsbEJKttidjo?Lt}Mtt}N|i|Oti |ndS(s Do basic configuration for the logging system by creating a StreamHandler with a default Formatter and adding it to the root logger. iN( slensrootshandlerss StreamHandlershdlrs Formatters BASIC_FORMATsfmts setFormatters addHandler(sfmtshdlr((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys basicConfigEs  cs2V[\|o]tii|Sn_tSdS(s Return a logger with the specified name, creating it if necessary. If no name is specified, return the root logger. N(snamesLoggersmanagers getLoggersroot(sname((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys getLoggerVs csNjmnttidjootnptti|f||dS(sD Log a message with severity 'CRITICAL' on the root logger. iN( slensrootshandlerss basicConfigsapplyscriticalsmsgsargsskwargs(smsgsargsskwargs((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pyscriticaljscsNtwxttidjoytnztti|f||dS(sA Log a message with severity 'ERROR' on the root logger. iN( slensrootshandlerss basicConfigsapplyserrorsmsgsargsskwargs(smsgsargsskwargs((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pyserrortscs-|tt|f|hdd<dS(sa Log a message with severity 'ERROR' on the root logger, with exception information. isexc_infoN(sapplyserrorsmsgsargs(smsgsargs((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys exception|scsNttidjotntti|f||dS(sC Log a message with severity 'WARNING' on the root logger. iN( slensrootshandlerss basicConfigsapplyswarningsmsgsargsskwargs(smsgsargsskwargs((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pyswarningscsNttidjotntti|f||dS(s@ Log a message with severity 'INFO' on the root logger. iN( slensrootshandlerss basicConfigsapplysinfosmsgsargsskwargs(smsgsargsskwargs((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pysinfoscsNttidjotntti|f||dS(sA Log a message with severity 'DEBUG' on the root logger. iN( slensrootshandlerss basicConfigsapplysdebugsmsgsargsskwargs(smsgsargsskwargs((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pysdebugscs|ti_dS(s= Disable all logging calls less severe than 'level'. N(slevelsrootsmanagersdisable(slevel((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pysdisablescsAx1tiD] }|i|iqWdS(s Perform any cleanup actions in the logging system (e.g. flushing buffers). Should be called at application exit. N(s _handlersskeysshsflushsclose(sh((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pysshutdowns   (Es__doc__ssyssosstypesstimesstrings cStringIOsthreads threadings ImportErrorsNones __author__s __status__s __version__s__date__slowers__file__s_srcfilespathsnormcaseshasattrs _startTimesraiseExceptionssCRITICALsFATALsERRORsWARNINGsWARNsINFOsDEBUGsNOTSETs _levelNamess getLevelNames addLevelNames_locks _acquireLocks _releaseLocks LogRecords makeLogRecords Formatters_defaultFormattersBufferingFormattersFiltersFilterers _handlerssHandlers StreamHandlers FileHandlers PlaceHolders _loggerClassssetLoggerClasssManagersLoggers RootLoggersrootsmanagers BASIC_FORMATs basicConfigs getLoggerscriticalsfatalserrors exceptionswarningswarnsinfosdebugsdisablesshutdown(:s cStringIOssetLoggerClasssFilterers _acquireLocksHandlerssyssshutdownstypessLoggers Formatters BASIC_FORMATs getLevelNamesFilterserrors addLevelNames getLoggers FileHandlersfatalsWARNINGs __status__s StreamHandlersNOTSETsCRITICALsraiseExceptionssinfos _handlerssstrings _startTimestimes exceptions __author__sWARNsdisableswarnsERRORsDEBUGsFATALs PlaceHoldersINFOs_defaultFormattersBufferingFormatters __version__s_srcfilesthreadsroots makeLogRecords _levelNamess__date__s threadingsManagerswarningscriticals _releaseLocksdebugs LogRecordsoss basicConfigs RootLogger((sU/home/users/jdub/public_html/bzr/planet/devel/trunk/planet/compat_logging/__init__.pys?s 9     #          ~   A | *%, /  S