I'd expect the program below to put only one line with "Eat me" in the log
file. However, I get this with Python 2.4.2 in WingIDE on Windows XP:
Eat me
Ignore me
My understanding is:
1. Event "Ignore me" is logged to logger 'spam'.
2. Logger 'spam' has no handler associated with it, so this logger doesn't
do anything with the event.
3. The event is dispatched to the root logger as well, since this is an
ancestor of 'spam'. This works as expected, since the event "Eat me" is
logged by the root logger.
4. The root logger has a Filter, which requires the logger of the event to
be 'ham', or offspring thereof. 'spam' is not offspring of 'ham' in the
dotted name hierarchy, so the event should be ignored.
So why does "Ignore me" end up in the logfile? What am I missing?
import logging
rootLogger = logging.getLogg er()
rootLogger.addH andler(logging. FileHandler(r'C :\Scratch\SiteC hecker\Sitechec ker.log'))
rootLogger.addF ilter(logging.F ilter('ham'))
rootLogger.setL evel(logging.DE BUG)
logging.getLogg er('ham.eggs'). info("Eat me")
logging.getLogg er('spam').info ("Ignore me")
logging.getLogg er().info("Igno re me too")
logging.shutdow n()
--
René Pijlman
Wat wil jij worden? http://www.carrieretijger.nl