Basically the problem is illustrated with the following example:
import gLogger
gLogger.setLevel('DEBUG')
# log has level debug
log = gLogger.getSubLogger('log')
sublog = log.getSubLogger('sublog')
sublog.setLevel('INFO')
log.error("changeLevel")
# should print "Framework/log ERROR: changeLevel"
sublog.error("changeLevel")
# should print "Framework/sublog ERROR: changeLevel"
log.debug("changeLevel")
# should print "Framework/log DEBUG: changeLevel"
sublog.debug("changeLevel")
# should NOT print "Framework/sublog DEBUG: changeLevel"
Even though the last line should not be printed, it is.
The reason is that sublog.setLevel loops over the Backends of sublog, and set their level to INFO. However, there is no backend attached to sublog ! Yet the message are displayed because the logger object of sublog has the value propagate to True (https://docs.python.org/2/library/logging.html#logging.Logger.propagate). In practice, this mean that we cannot really change levels or options of sublogers.
The levels are managed in a strange way: the logger level is always debug, and a Logging.setLevel just changes the level of the Backends (so of the handlers). This was done in order to make sure that the centralized logging could not be disabled.
I cannot think of a way to make our code work, while not re-implementing basically what logging does, which is exactly what we want to avoid.
Setting propagate to False would mean duplicating the backend to the child, which is not necessarily thread safe (think of the logs being written to a file: there would be several file handlers on the same file).
Creating FacadeBackend to just pretend that the parent backend belongs to the child is also not an option, because we would still not be able to change the level of subloggers.
From the top of my head, the only option I see is to relax the constraint we have on the centralized logging, and accept that some stuff may get disabled by the developers...
I keep this as a note for me for later
Basically the problem is illustrated with the following example:
Even though the last line should not be printed, it is.
The reason is that
sublog.setLevelloops over theBackendsofsublog, and set their level toINFO. However, there is no backend attached tosublog! Yet the message are displayed because theloggerobject ofsubloghas the valuepropagateto True (https://docs.python.org/2/library/logging.html#logging.Logger.propagate). In practice, this mean that we cannot really change levels or options of sublogers.The levels are managed in a strange way: the
loggerlevel is alwaysdebug, and aLogging.setLeveljust changes the level of theBackends(so of thehandlers). This was done in order to make sure that the centralized logging could not be disabled.I cannot think of a way to make our code work, while not re-implementing basically what
loggingdoes, which is exactly what we want to avoid.Setting
propagatetoFalsewould mean duplicating the backend to the child, which is not necessarily thread safe (think of the logs being written to a file: there would be several file handlers on the same file).Creating
FacadeBackendto just pretend that the parentbackendbelongs to the child is also not an option, because we would still not be able to change the level of subloggers.From the top of my head, the only option I see is to relax the constraint we have on the centralized logging, and accept that some stuff may get disabled by the developers...
I keep this as a note for me for later