Issue 8327: unintuitive behaviour of logging message propagation (original) (raw)

Hello

Crawling into the logging module, I've just discovered its behaviour was actually far from the one I expected, in a consequent gap that the documentation had left.

I thought that depending on the "propagate" parameter of each logger, a message would always try to propagate up the logger hierarchy, and that if that message matched the level of a logger (as well as the global disable() level), then this message would be tested against each handler of that logger.

But it's not at all the way it is : actually, only the level of the "entrance" logger is checked ; if the message is blocked by it, it's the end, parent loggers will never hear about it (even thoiugh they might have a lower level set). On the contrary, if that entrance logger accepts the message, then ALL handlers from the hierarchy are snet the message, without caring about the own level of their related logger.

That's really not the behaviour I would have expected, considering the global_disable > logger_level > handler_level precedence that the doc implicitly showed. Are there rationales behind this that I'm lacking ?

So I'd advocate either (if possible) a patching of the logging system, to reflect that semantic ; or the adding of comprehensive paragraphs to teh doc, to explain what the exact relationship between levels and propagation attribuets are. Just tell me if a patch is conceivable B-)

Thanks for the doc patch, if you don't mind I'd just add the paragraph below too, to clarify the fact that logger levels are only "entry points" levels, ignored he rest of the time. There might be slight redundancies with the rest of the (long) documentation, but it's all benefit imo. B-)

"In addition to any handlers directly associated with a logger, all handlers associated with all ancestors of the logger are called to dispatch the message (unless the propagate flag for a logger is set to a false value, at which point the passing to ancestor handlers stops).

Note that in this process, the level of ancestor loggers is never considered : only their propagate attribute and the levels of their loggers canimpact the treatment on the message being dispatched. The level of a logger is thus only acting as an entry point barrier, only able to stop the whole dispatch of a message that enters the system through it."