logging

Vinay Sajip vinay_sajip at yahoo.co.uk
Thu Jun 1 00:05:13 CEST 2006


ibr at radix50.net wrote:

> Hello Vinay,
>
> Hmm, log1 decides once whether to print an event, and after that it gets
> printed in log1 and all its ancestors, regardless of their level? I find
> this quite counter-intuitive. I'd instead expect that each logger
> decides whether to print an event according to its own level. Could you
> give an example why one would want the python behavior?

Loggers are hierarchical for a reason - not just randomly named
channels. Just as it is generally useful to develop a system by
modularising it into subsystems, packages, modules, etc. so it is
useful when logging to follow a parallel hierarchy. The audiences for
the logging events are orthogonal to the events themselves, and the way
the logging module is organised reflects good practice as determined by
practical experience over a period of time. The approach you're
questioning is not specific to Python - log4j (which inspired Python's
logging), and the logging built into Java 1.4, also work this way.
Practically, this makes configuration a lot simpler; if I want to log
everything to console, I just attach a handler to the root logger, and
I never have to worry about attaching to every single logger. (Logger
names are generally not cast in stone - I might break down a module's
logic into smaller pieces and thus introduce new logger names to
describe events in the refactored module. I certainly don't want to
change my logging configuration every time I refactor my code.)

May I suggest you review the log4j documentation to get a better
exposition of the principles which govern the design of such logging
systems.




More information about the Python-list mailing list