Notice how this can easily be captured into a file you might name as logconfig.py
You might be wondering how to assign an attribute to a function, like sendmail.to?
In this particular case, sendmail is actually a class that masquerades as a function.
>>> class Sendmail:
... to = None
...
... def __call__(self, level, module, msg, exc):
... # et. c
...
>>> sendmail = Sendmail()
This way, the most common use-case, i.e. to be notified when something happens is easy to apply, while more complicated ones are only a short step away.
Thanks. I like the idea of classes masquerading as functions. And easier configuration. I had actually started writing this 2 days ago as something just for me, but after reading this decided to try something new.
With something that can happen as often as logging, make sure that you test it when accessed from multiple python threads, and pound the crap out of it in various typical configurations. Python’s default logging can be a real dog, and at least in one project I was working on a few years ago turned out to be a real bottleneck.
[1] https://github.com/peterldowns/lggr