[Yum-devel] Using python's logging module

James Bowes jbowes at redhat.com
Mon Apr 24 20:30:22 UTC 2006


Hi all:

How would everyone feel about moving yum from using a custom logger 
implementation to using python's standard logging module[1, 2]?

The path I've been taking so far is to map yum's levels to logging's 
levels like so:

ERRORLOG:   0       0       CRITICAL
             1       1       CRITICAL
             2       2       ERROR
             3       3       ERROR

LOG:        1       4       WARN
             2       5       WARN
             3       6       INFO
             4       7       INFO
             5       8       INFO
             6       9       DEBUG
             7      10       DEBUG

Then in the configuration, CRITICAL and ERROR would go to stderr, and 
the others would go to stdout.

It would be possible to define additional logging levels to have a 
1-to-1 mapping from yum.logger to logging. Personally, I feel that five 
levels are enough.

The information sent to syslog and yum.log is pretty specific, so for 
that I've been using a specific log namespace (yum.syslog, for now). 
Everything sent to that logger would be sent to syslog and yum.log.

In the medium-term, it might be good to re-examine a lot of the 
information set to self.log, specifically in cli.py, output.py, and 
shell.py. Most of that output feels like extra detail for the 
command-line ui, and could be better off being dealt with by a system 
separate from logging. Then all logging information could be sent to stderr.

For configuration, a logging config file could live in yum's etc dir. 
Command-line options for -d -e would override it, of course.

Some rationale behind this:

- No need to maintain a distinct logging module in yum. Less code is good.
- Decouples objects. Each object can call logging.getLogger() instead of 
passing log objects around.
- Configuration can be done in the conf file rather than in code. Again, 
less code is good.
- Effectively completes the plugin TODO about logging. Users can simply 
modify their config file to send logging output wherever they choose.

So, what are everyone's thoughts?

-James


[1] http://docs.python.org/lib/module-logging.html
[2] http://www.python.org/dev/peps/pep-0282/



More information about the Yum-devel mailing list