Logo Search packages:      
Sourcecode: yum version File versions  Download package

yum::logger Namespace Reference

Detailed Description

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


  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


  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:
  -1     failure - cannot be ignored
   0     important message - printed in default mode
   1     informational message - printed with -v
   2     debugging information

  -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.


  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.


  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.


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


  I welcome comments, questions, bug reports and requests... I'm very
  lonely. :)


class  LogContainer
class  Logger
class  SysLogger


def printtime


string AUTHOR = "Michael D. Stenner <mstenner@phy.duke.edu>"
tuple cont = LogContainer([log, log2], threshold=0)
string DATE = "2003/09/20"
tuple log = Logger(threshold, preprefix = 'TEST ')
tuple log2 = Logger(threshold-2, preprefix = 'LOG2 ')
tuple slog = SysLogger(3, 'logger-test')
string stuff = 'abcd\nefgh\nijkl'
int threshold = 3
string URL = "http://linux.duke.edu/projects/mini/logger/"
string VERSION = "0.7"

Generated by  Doxygen 1.6.0   Back to index