MINI SHELL

Server : Apache/2.2.2 (Fedora)
System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686
User : apache ( 48)
PHP Version : 5.2.9
Disable Function : NONE
Directory :  /proc/self/root/proc/self/root/usr/lib/python2.4/site-packages/yum/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/self/root/proc/self/root/usr/lib/python2.4/site-packages/yum/logger.pyc
mò
ýÉODc@sØdZdkZdkZdZdZdZdZdfd„ƒYZdfd	„ƒYZd
fd„ƒYZ	e
djo^d
ZdeGHeeddƒZdGHx(e
ddƒD]Zeedeƒq¬WdGHdkZd„Zee_dGHx(e
ddƒD]ZeedeƒqüWdGHdGHeedddƒZe	eegddƒZeie_dGHx(e
ddƒD]ZeedeƒqpWdGHd Zd!GHeeƒd"GHeed#ƒd$GHeed%ƒd&GHed#ƒd'GHeied#ƒd(GHed)hd*d+<ƒd,GHde_ed-ƒeid-ƒeid)oeid)d.jpd/GHd0GHeidƒnd1GHd2GHed
d3ƒZd4GHd5GHx(e
ddƒD]Zeedeƒq Wd6GHeidd7ƒndS(8s 

A module for convenient yet powerful file, console, and syslog logging

BASIC USAGE

  from logger import Logger

  log = Logger(threshold=0)    # create the log object and give it
                               # a threshold of 0
  log.log(2, 'all done')       # send a log of priority 2 (not printed)
  log(0, 'error: bandits!')    # send a log of priority 0 (printed)
  log.write(0, stringvar)      # do a raw write on the file object

DESCRIPTION

  Each logging object is given a threshold.  Any messages that are
  then sent to that object are logged only if their priority meets or
  exceeds the threshold.  Lower numerical priority means that a
  message is more important.  For example: if a log object has
  threshold 2, then all messages of priority 2, 1, 0, -1, etc will be
  logged, while those of priority 3, 4, etc. will not.  I suggest the
  following scale:
  
     LOG PRIORITY    MEANING
              -1     failure - cannot be ignored
               0     important message - printed in default mode
               1     informational message - printed with -v
               2     debugging information

        THRESHOLD    MEANING
              -1     quiet mode (-q) only failures are printed
               0     normal operation
               1     verbose mode (-v)
               2     debug mode (-vv or -d)

  It can be extended farther in both directions, but that is rarely
  useful.  It can also be shifted in either direction.  This might be
  useful if you want to supply the threshold directly on the command
  line but have trouble passing in negative numbers.  In that case,
  add 1 to all thresholds and priorities listed above.

CLASSES

  There are three primary classes defined in this module:

    Logger        Class for basic file and console logging
    SysLogger     Class for syslog logging
    LogContainer  Class for wrapping multiple other loggers together
                  for convenient use

  Instances of all of these support the same basic methods:

    obj.log(priority, message)   # log a message with smart formatting
    obj.write(priority, message) # log a string in a ver raw way
    obj(priority, message)       # shorthand for obj.log(...)

  Different classes support other methods as well, but this is what you
  will mostly use.


ADVANCED

  There are a number of options available for these classes.  These are
  documented below in the respective classes and methods.  Here is a
  list of some of the things you can do:

    * make a prefix contain a string which gets repeated for more
      important logs.  (prefix)
    * directly test if a log object WOULD log, so you can do
      complicated stuff, like efficient for loops. (test)
    * make the priority, threshold arbitrary objects, with a
      home-rolled test to see if it should log. (test)
    * give log containers a "master threshold" and define arbitrary
      behavior based on it.  Examples include:
      - only pass on messages of sufficient priority (ragardless of
        the thresholds of the log ojects).
      - only pass on messages to objects whose thresholds are
        (numerically) lower than the master threshold.

SEE ALSO

  Take a look at the examples at the end of this file in the test &
  demo section.

COMMENTS

  I welcome comments, questions, bug reports and requests... I'm very
  lonely. :)
Ns*Michael D. Stenner <mstenner@phy.duke.edu>s0.7s
2003/09/20s+http://linux.duke.edu/projects/mini/logger/tLoggercBshtZdZdeidddddd„Zd„Zd„Zed„Z	e	Z
ed	„Zd
„ZRS(sÛ
A class for file-object logging
    
    USAGE:
      from logger import Logger

      log_obj = Logger(THRESHOLD)     # create the instance

      log_obj.log(3, 'message')       # log a message with priority 3
      log_obj(3, 'message')           # same thing
      log_obj(3, ['message'])         # same thing

      log_obj.test(3)                 # boolean - would a message of
                                      # this priority be printed?

      # a raw write call after the priority test, for writing
      # arbitrary text -- (this will not be followed by \n)
      log_obj.write(3, 'thing\nto\nwrite')  

      # generate the prefix used for priority 3
      pr = log_obj.gen_prefix(3)

      # see the examples in the test section for more

    BASIC OPTIONS:

      There are a couple of basic options that are commonly needed.
      These are attribues of instances of class Logger.

        preprefix

          Text that will be printed at the start of each line of
          output (for log()ged, not write()en messages).  This might
          be your program's name, for example.

            log.preprefix = 'myprog'

          If preprefix is callable, then it will be called for each
          log and the returned value will be used.  This is useful for
          printing the current time.

            import time
            def printtime():
                return time.strftime('%m/%d/%y %H:%M:%S ',
                         time.localtime(time.time()))
            log.preprefix = printtime
      
        file_object

          This is the file object to which output is directed.  If it
          is None, then the logs are quietly dropped.

      There are other options described in the next section, but these
      are the most commonly used.

    ATTRIBUTES:
      (all of these are settable as keyword args to __init__)

      ATTRIBUTES   DEFAULT      DESCRIPTION
      ----------------------------------------------------------
      threshold    = 0          how verbose the program should be
      file_object  = sys.stderr file object to which output goes
      prefix       = ''         prefix string - repeated for more
                                important logs
      prefix_depth = 5          times prefix is repeated for logs
                                of priority 0.  Basically, set this
                                one larger than your highest log
                                priority.
      preprefix    = ''         string printed before the prefix
                                if callable, returned string will
                                be used (useful for printing time)
      postprefix   = ''         string printed after the prefix
      default      = 1          default priority to log at

    itiicCsC||_||_||_||_||_||_||_dS(N(t	thresholdtselftfile_objecttprefixtprefix_deptht	preprefixt
postprefixtdefault(RRRRRRRR	((t./usr/lib/python2.4/site-packages/yum/logger.pyt__init__Às						cCst|iƒt|ƒjS(sA
        Return true if a log of the given priority would be printed.
        
        This can be overridden to do any test you like.  Specifically,
        priority and threshold need not be integers.  They can be
        arbitrary objects.  You need only override this method, and
        possibly gen_prefix.
        N(tintRRtpriority(RR
((R
ttestÐs	cCs“t|iƒo|iƒ}n
|i}|ioU|it|ƒ}|djo
d}nx(td|ƒD]}||i}qmWn||i
S(s*
        Return the full prefix (including pre and post) for the
        given priority.

        If you use prefix and use a more complicated priority and
        verbosity (non-numerical), then you should either give the
        chosen object a __int__ method, or override this function.
        iiN(tcallableRRRRRR
tdepthtrangetiR(RR
RRR((R
t
gen_prefixÝs		


cCs	|i||ƒ\}}|i|ƒoÝ|idjodSnt	|ƒt	dƒjo2t
i|dƒ}|ddjo|d=qÉn?t	|ƒt	gƒjot
t
i|ƒ}nt|ƒg}|i|ƒ}x*|D]}|ii||dƒqßWndS(su
        Print a log message.  This prepends the prefix to each line
        and does some basic formatting.
        NRs
iÿÿÿÿ(Rt_use_defaultR
tmessagetptmRRtNonettypetstringtsplittmlisttmaptrstriptstrRRtlinetwrite(RR
RRRRRR ((R
tlogós cCsX|i||ƒ\}}|i|ƒo,|idjodSn|ii	|ƒndS(s™
        Print a log message.  In this case, 'message' must be a string
        as it will be passed directly to the file object's write method.
        N(
RRR
RRRRRRR!(RR
RRR((R
R!	scCs,|djo|i|fSn||fSdS(s0Substitute default priority if none was providedN(RRRR	R
(RR
R((R
Rs
(
t__name__t
__module__t__doc__tsyststderrRRRRR"t__call__R!R(((R
RtsJ!	
	
t	SysLoggercBsktZdZdeddddd„Zd„Zd„Zd„Zed„ZeZ	ed	„Z
d
„ZRS(s2	A class for file-object logging
    
    USAGE:
      For the most part, SysLogger instances are used just like Logger
      instances.  Notable exceptions:

        * prefixes aren't used (at least not as they are for Logger)
        * map_priority is pretty important because it controls
          conversion between Logger priorities and syslog priorities
        * although priority/threshold/test works the same, there is
          also maskpri and your syslog config which will limit what
          gets logged.  Keep this in mind if you see strange behavior.

      The most sensible use of this class will be will a LogContainer.
      You can create one Logger instance for writing to (say) stderr,
      a second for writing to a verbose log file, and a SysLogger
      instance for writing important things to syslog so your automated
      log-readers can see them.  Then you put them all in a log container
      for convenient access.  That would go something like this:

        from logger import Logger, SysLogger, LogContainer
        
        fo = open(file_log, 'w')
        file_logger    = Logger(4, file_object=fo) # print 4 and lower
        console_logger = Logger(1)                 # print 1 and lower
        syslog_logger  = SysLogger(0)              # print 0 and lower
        log = LogContainer([file_logger, console_logger, syslog_logger])

        log(3,  'some debugging message') # printed to file only
        log(1,  'some warning message')   # printed to file and console
        log(0,  'some error message')     # printed to all (ERR level)
        log(-1, 'major problem')          # printed to all (CRIT level)
      
    ATTRIBUTES:
      (all of these are settable as keyword args to __init__)

      ARGUMENT     DEFAULT      DESCRIPTION
      ----------------------------------------------------------
      threshold    = 0          identical to Logger threshold
      ident        = None       string prepended to each log, if None,
                                it will be taken from the program name
                                as it appears in sys.argv[0]
      logopt       = 0          syslog log options
      facility     = 'LOG_USER' syslog facility (it can be a string)
      maskpri      = 0          syslog priority bitmask
      default      = 1          default priority to log at

    itLOG_USERicCsÓdka||_||_|djoPtiti	ddƒ}|djoti	d}qxti	d|d}nt|ƒtdƒjot
t|ƒ}nti|||ƒ|oti|ƒndS(Nit/iÿÿÿÿiR(tsyslogRRR	tidentRRtrfindR&targvtindRtfacilitytgetattrtopenlogtlogopttmaskprit
setlogmask(RRR-R4R1R5R	R0((R
RJs				

cCs
ti|ƒS(s9a (very) thin wrapper over the syslog setlogmask functionN(R,R6R5(RR5((R
R6dscCs|dS(sTake a logger priority and return a syslog priority

        Here are the syslog priorities (from syslog.h):
          LOG_EMERG       0       /* system is unusable */
          LOG_ALERT       1       /* action must be taken immediately */
          LOG_CRIT        2       /* critical conditions */
          LOG_ERR         3       /* error conditions */
          LOG_WARNING     4       /* warning conditions */
          LOG_NOTICE      5       /* normal but significant condition */
          LOG_INFO        6       /* informational */
          LOG_DEBUG       7       /* debug-level messages */

        The syslog priority is simply equal to the logger priority plus 3.

           0 ->  0 + 3 =  3
          -5 -> -5 + 3 = -2  (which will be treated as 0)

        You can override this very simply.  Just do:

        def log_everything_emerg(priority): return 0
        log_obj.map_priority = log_everything_emerg

        The return value of this function does not need to be an integer or
        within the allowed syslog range (0 to 7).  It will be converted to
        an int and forced into this range if it lies outside it.
        iN(R
(RR
((R
tmap_priorityhscCst|iƒt|ƒjS(sg
        Return true if a log of the given priority would be printed.
        
        This can be overridden to do any test you like.  Specifically,
        threshold and threshold need not be integers.  They can be
        arbitrary objects.  If you override this and use non-integer
        priorities, you will also need to override map_priority.
        N(RRRR
(RR
((R
R…scCs|i||ƒ\}}|i|ƒoñt|ƒtdƒjo2ti	|dƒ}|ddjo|d=q±n?t|ƒtgƒjotti|ƒ}nt
|ƒg}t|i|ƒƒ}|djo
d}n|djo
d}nx"|D]}ti||ƒqûWndS(sB
        Print a log message with some simple formatting.
        Rs
iÿÿÿÿiiN(RRR
RRRRRRRRRRRRR7tspR R,(RR
RRR8RRR ((R
R"s$



cCsÂ|i||ƒ\}}|i|ƒo–t|i|ƒƒ}|djo
d}n|djo
d}nt
i|dƒ}|ddjo|d=nx"|D]}t
i
||ƒq WndS(s&
        Print a log message.
        iis
iÿÿÿÿRN(RRR
RRRRRR7R8RRRR,(RR
RRR8RR((R
R!¥s



cCs,|djo|i|fSn||fSdS(s0Substitute default priority if none was providedN(RRRR	R
(RR
R((R
Rµs
(R#R$R%RRR6R7RR"R(R!R(((R
R)s0			tLogContainercBsktZdZgedd„Zd„Zed„ZeZed„Zd„Z	d„Z
d„Zd	„ZRS(
s	A class for consolidating calls to multiple sub-objects

    SUMMARY:
      If you want a program to log to multiple destinations, it might
      be convenient to use log containers.  A log container is an
      object which can hold several sub-log-objects (including other
      log containers).  When you log to a log container it passes the
      message on (with optional tests) to each of the log objects it
      contains.

    USAGE:

      The basic usage is very simple.  LogContainer's simply pass on
      logs to the contained Logger, SysLogger, or LogContainer
      objects.

        from logger import Logger, LogContainer

        log_1 = Logger(threshold=1, file_object=sys.stdout)
        log_2 = Logger(threshold=2, preprefix='LOG2')

        log = LogContainer([log_1, log_2])

        log(1, 'message')               # printed by log_1 and log_2
        log(2, 'message')               # only printed by log_2

      A more common example would be something like this:
      
        from logger import Logger, LogContainer

        system = Logger(threshold=1, file_object=logfile)
        debug  = Logger(threshold=5, file_object=sys.stdout)
        log = LogContainer([system, debug])

        log(3, 'sent to system and debug, but only debug will print it')
        log(0, 'very important, both will print it')

      In this mode, log containers are just shorthand for calling all
      contained objects with the same priority and message.

      When a log object is held in a container, it can still be used
      directly.  For example, you can still do

        debug(3, ['this will not be sent to the system log, even if its',
                  ' threshold is set very high'])

      (Yes, you can send lists of strings and they will be formatted
      on different lines.  The log methods are pretty smart.)

      There are more examples in the SysLogger docs.

    ATTRIBUTES:
      (all of these are settable as keyword args to __init__)

      ATTRIBUTES   DEFAULT      DESCRIPTION
      ----------------------------------------------------------
      list         = []         list of contained objects
      threshold    = None       meaning depends on test - by default
                                threshold has no effect
      default      = 1          default priority to log at

    icCs||_||_||_dS(N(tlistRRR	(RR:RR	((R
Rûs		cCs|ii|ƒdS(s"Add a log object to the container.N(RR:tappendtlog_obj(RR<((R
taddscCs`|i||ƒ\}}xA|iD]6}|i|||i	|ƒo|i
||ƒq"q"WdS(s_Log a message to all contained log objects, depending on
        the results of test()
        N(RRR
RRRR:R<RRR"(RR
RR<RR((R
R"s
cCs`|i||ƒ\}}xA|iD]6}|i|||i	|ƒo|i
||ƒq"q"WdS(N(RRR
RRRR:R<RRR!(RR
RR<RR((R
R!s

cCs,|djo|i|fSn||fSdS(s0Substitute default priority if none was providedN(RRRR	R
(RR
R((R
Rs
cCsdS(sUTest which log objects should be passed a given message.

        This method is used to determine if a given message (and
        priority) should be passed on to a given log_obj.  The
        container's threshold is also provided.

        This method always returns 1, and is the default, meaning that
        all messages will get passed to all objects.  It is intended
        to be overridden if you want more complex behavior.  To
        override with your own function, just do something like:

          def hell_no(p, m, t, object): return 0
          container.test = hell_no
        iN((RR
RRR<((R
RscCs
||jS(sÞOnly pass on messages with sufficient priority compared to
        the master threshold.

          container = LogContainer([system, debug], threshold = 2)
          container.test = container.test_limit_priority
        N(R
R(RR
RRR<((R
ttest_limit_priority+scCs
|i|jS(sõOnly pass on messages to log objects whose threshold is
        (numerically) lower than the master threshold.

          container = LogContainer([system, debug], threshold = 2)
          container.test = container.test_limit_threshold
        N(R<R(RR
RRR<((R
ttest_limit_threshold4s(
R#R$R%RRR=R"R(R!RRR>R?(((R
R9ºs>						t__main__isTHRESHOLD = %sRsTEST  s Lets log a few things!iþÿÿÿi
slog priority %ss,
 Now make it print the time for each log...cCstidtitiƒƒƒS(Ns%m/%d/%y %H:%M:%S (ttimetstrftimet	localtime(((R
t	printtimeIss and log a few more thingss<
 now create another with a different prefix and priority...s and put them in a container...isLOG2 Ris and log a bit mores:
 OK, enough of the container... lets play with formattingsabcd
efgh
ijkls
 no trailing newlines
 with trailing newlines
s
 two trailing newliness

s
 log JUST a newlines/
 use the write method, with a trailing newlines
 print some complex objectitkeytvalues=
 now set the file object to None (nothing should be printed)sTHIS SHOULD NOT BE PRINTEDR,s<
 skipping syslog test (because they would annoy your admin)s8 add "syslog" to the command line to enable syslog testss
 performing syslog testss" creating logger with threshold: 3slogger-tests6 logging at (logger) priorities from -2 to 9 (but onlys priorities <= 3 should show ups
 now test the write() methods!first line
second line
third line(R%R&RtAUTHORtVERSIONtDATEtURLRR)R9R#RR"RRRARDRtlog2tcontR>RtstuffR!RRR/texittslog(RLRDR9RRR"RGR)RORKRRJR&RHRIRRMRA((R
t?Ys„		¤¢ƒ
				

	

"

Anon7 - 2021