[Tutor] Subclassing logging.Handler?

Alex Hall ahall at autodist.com
Wed Jul 6 08:32:35 EDT 2016


Hey list,
Another day, another Python experiment. I'm wondering what methods I'd have
to implement in a custom subclass of logger.Handler.

Currently, the recurring jobs I have written log their events to a file
each time they run. That's fine, but it doesn't let me keep
easily-sorted/searched records. Even if I use a size-based log file
handler, it'll get hard to search. I'm pondering logging to a database as
well, so that the files will always have the most recent few runs, but the
database will have everything. That means subclassing logger.Handler.

I found the docs for this, but is emit() the only function I need to
implement? There are things about i/o locks, formatting, and so on as well.
How much do I need to do, and how much can I leave up to the super class?
I'll have to call
super(MyLogHandler, self).__init__()
I know, but what else do I have to worry about? To be clear, I'm not asking
about logging to a database, only what to do to make a Handler subclass
capable of logging through whatever mechanisms I want. Thanks.

-- 
Alex Hall
Automatic Distributors, IT department
ahall at autodist.com


More information about the Tutor mailing list