Here is a small example of something I find very weird about the logging
module:
import logging
logging.basicConfig()
#
# making a hierarchy like this:
# root
# |- session
# |-session.foo
#
root_logger = logging.getLogger()
session_logger = logging.getLogger("session")
foo_logger = logging.getLogger("session.foo")
#
# root_logger and session_logger effective log levels
# are set to 30 (= WARNING)
#
foo_logger.debug("WA") #nothing is printed, so far so good
#
# and now enters the problem...
#
foo_logger.setLevel(logging.DEBUG)
foo_logger.debug("HELLO") #HELLO log message is printed!!!
I do not get why the 'HELLO' log message is printed, to my understanding
since there is no handler attached to logger foo_logger
the log message should
bubble up, and effectively be stopped by higher level logger (session
),
since its level is set to WARNING
(by default).
It seems like setting the level on foo_logger
gives it rights to display
through the handler but it is very unclear to me.
Can someone explain to me why the message is printed ? And what should I do to have the logger hierarchy as I would like ?