logging module: problem with custom handlers

Neil Padgen neil.padgen at mon.bbc.co.uk
Tue Oct 28 07:54:50 EST 2003


>>>>> "Peter" == Peter Otten <__peter__ at web.de> writes:

    Peter> I do not know if there is an "official" way to achieve the
    Peter> same, but then, why would you build your own Handler in the
    Peter> first place?

I've just done exactly the same approach (independently), because of a
need to build two Handlers of my own.  One is to avoid tracebacks
being logged with a SysLogHandler (it makes the syslog messages too
long, so nothing is logged), and the other is a subclass of
SMTPHandler which changes the subject of the mail if an exception of a
certain type is raised. [1]

I can think of plenty of other instances where building a custom
Handler is needed; for example, an SQLHandler which might log messages
to a database.

[1] This might be better done with a different Formatter, but getting
a custom Formatter to be used by logging.config is much harder than a
custom Handler, due to logging.Formatter() being called from within
logging.config.fileConfig().

Personally I think logging.config.fileConfig()  is in need of some
serious refactoring... if only I had time to look into it!

-- Neil




More information about the Python-list mailing list