Somewhere in the bowels of my code I have something like:
logger = logging.getLogger('debug0.x')
The way I understand it, this should only respond when I have previously done something like:
logging.basicConfig(filename='10Nov2010a.txt',level=logging.DEBUG, name='debug0')
note that name has been defined as debug0. However, I have discovered that if do
logging.basicConfig(filename='10Nov2010a.txt',level=logging.DEBUG)
without the name keyword, then the debug0.x logger defined above reacts, and writes to the log file. I was thinking it would only react in the first case, when the logger had been named.
I'm confused.
The Python
logging
module organizes loggers in a hierarchy. All loggers are descendants of the root logger. Each logger passes log messages on to its parent.New loggers are created with the
getLogger()
function. The function calllogging.getLogger('debug0.x')
creates a loggerx
which is a child ofdebug0
which itself is a child of the root logger. When logging to this logger, it will pass on the message to its parent, and its parent will pass the message to the root logger. You configured the root logger to log to a file by thebasicConfig()
function, so your message will end up there.If you check out the code or the doc:
logging.basicConfig does not use name argument at all. It initializes the root logger. While getLogger takes a "name" argument