I'm just an idiot when it comes logging

olsongt at verizon.net olsongt at verizon.net
Sun Mar 20 23:25:20 CET 2005


I'm trying to be a good boy and use the logging module but it's
behaving rather counter-intuitively.  I've posted a simplified test
script below.

To summarize, I've set the basic config to only log root level messages
with >= ERROR level.  I've created another named logger that logs on
info level.  I've set it up so it just shows the message text without
"INFO:: logger:" boilerplate.

The way I see things, when I call otherLogger.info, it should propogate
the message to the root logger, but the root logger should discard it
since it is at ERROR level.

Could someone explain what I'm not getting?

-Grant

###
### logging_test.py
###

import logging

logging.basicConfig(level=logging.ERROR)

root = logging.getLogger('')

otherLogger = logging.getLogger("logger")
otherLogger.setLevel(logging.INFO)

console = logging.StreamHandler()
console.setLevel(logging.INFO)
formatter = logging.Formatter("%(message)s")
console.setFormatter(formatter)

otherLogger.addHandler(console)

root.info("Shouldn't print") # lower level
root.error("Should Print") #higher level

otherLogger.info("Should only print once")

root.info("Shouldn't print") # lower level




More information about the Python-list mailing list