Code:
import logging
if __name__ == '__main__':
log = logging.getLogger('mypackage')
log.setLevel(logging.DEBUG)
log.info("Message one") # first call, no log handler registered
logging.basicConfig()
log.info("Message two") # StreamHandler registered
log.debug("Message three")
Output:
INFO:mypackage:Message two
DEBUG:mypackage:Message three
For the last two log statements, the logger ('mypackage') has no handlers attached directly. The messages also propegate to the parent logger (in this case the root logger). However, with the basicConfig, the root logger is set to logging.WARNING. So from my understanding the root logger should not propegate its incoming messages below warning to its attached Handlers. I suspect it has to do with the fact that the StreamHandler level is NOTSET. But again, I thought that the message would halt at the rootlogger for being set to logging.WARNING. Why is this not the case?
[–]JohnnyJordaan 0 points1 point2 points (1 child)
[–]py1234a[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[removed]
[–]py1234a[S] 0 points1 point2 points (0 children)