PEP 282: A Logging System

Denis S. Otkidach ods at fep.ru
Wed Apr 10 08:20:29 EDT 2002


I like the idea of logging system in standard Python library. The
interface described in PEP is very interesting. But there are things to
be discussed.

First it's very slow. Here are timings obtained from my test script
(http://ods.pp.ru/logging/logtest.py):
---
simplelog (log): 0.59
simplelog (ignore): 0.07
logging (log): 212.88
logging (ignore): 0.42
logging (log, no inspect/thread): 3.25
logging (ignore, no inspect/thread): 0.42
---
That's mainly due to unnecessary inspect calls. Vinay said that he fixed
this problem in upcomming release, but the module is still slow. I'm not
sure what we realy need: not-so-complicated but fast logging system or
extremly flexible and a bit slow? I guess it should be very fast at
least when logging is disabled.

May we should use lazy evaluation of some time-consuming properties
(filename/lineno, asctime)?

Default behavior of logging is to log all messages: if no handlers
found on first call, default is installed.  That's strange.  I guess it
should produce no log messages by default, i.e. no default handlers
should be installed.

I dislike the idea to import (and use for locking) thread module even
when application is not threaded. This is a general problem with many
modules. May be we need a atexit-like registry of functions that will be
called on first thread import?

The filter interface (object with filter method) is defined so that even
simple filters cannot defined inline. It can be changed to require any
callable object (instance with __call__ method or just an inlined
lambda). Vinay said that this make it less readable for newbies, but I'm
not sure he is right.

The most usefull filter (after simple setting the minimum log level) I guess should be a name filter. Something like this (I've replaced filter method with __call__):
def NameFilter:
    def __init__(self, name):
        self.name = name
        self.length = len(name)
    def __call__(self, record):
        return record.name.startswith(self.name) and \
                   (len(record.name)==self.length or
                    record.name[self.length:self.length+1]==',')







More information about the Python-list mailing list