[Tutor] Extending logging module

jay titleistfour at gmail.com
Thu Aug 9 16:40:05 CEST 2007


I've been using the python logging module a lot lately, and I've come across
an instance where I need some new levels.  Specifically, python does not
include ALERT and NOTICE in the default set of logging levels.  I am
wondering how trivial it would be to extend the logging module to include
these 2 levels that are standard with syslog?

My first test was just to use the addLevelName method to add the two new
levels, but syslog ignores them and logs at the next highest priority, no
matter what I use.

Looking further into the code and as a test, I changed the following to see
if this would even work

  -> class Logger
  -> add new notice and alert root level functions
  -> new _levelNames for notice and alert
  -> new default level names for notice and alert

  -> class SysLogHandler priority_map was changed to include notice and

It actually worked, but this is not the way I would like to handle the
problem.  I would prefer to extend the classes instead.  However, I'm not
too familiar with that, and I had to change things in so many places, I'm
wondering if its even possible?  I don't like changing the standard
libraries, what happens if I have to upgrade python?  My changes get

Can anyone offer some help or suggestions?  Thanks

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070809/9fbee351/attachment.html 

More information about the Tutor mailing list