This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: unintuitive behaviour of logging message propagation
Type: Stage:
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: eric.smith, pakal, vinay.sajip
Priority: normal Keywords:

Created on 2010-04-06 17:21 by pakal, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg102477 - (view) Author: Pascal Chambon (pakal) * Date: 2010-04-06 17:21
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-)
msg102484 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2010-04-06 19:00
Please see the following link for a rationale of the logging package's design:

http://plumberjack.blogspot.com/2009/09/python-logging-101.html

No patch to the logging system's code is planned, as it is working according to its design. The documentation will be gradually attended to as time allows, and patches will be considered.
msg102501 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2010-04-06 22:33
Documentation updated (r79876).
msg102521 - (view) Author: Pascal Chambon (pakal) * Date: 2010-04-07 08:05
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."
History
Date User Action Args
2022-04-11 14:56:59adminsetgithub: 52574
2010-04-07 08:05:46pakalsetmessages: + msg102521
2010-04-06 22:33:05vinay.sajipsetstatus: open -> closed
resolution: fixed
messages: + msg102501
2010-04-06 19:00:22vinay.sajipsetnosy: + vinay.sajip
messages: + msg102484

assignee: vinay.sajip
components: + Documentation, - Library (Lib)
2010-04-06 18:19:49eric.smithsetnosy: + eric.smith
2010-04-06 17:21:04pakalcreate