Logger vs. Handler log levels
steveg at moregruel.net
Thu Jun 21 23:05:01 CEST 2007
Apparently I don't understand logging levels. The code:
import logging, logging.handlers
newlog = logging.handlers.TimedRotatingFileHandler(
logging.info("Message from logtest")
logging.debug("Debug message from logtest")
doesn't print on the console (as expected), but also doesn't add the
first message to the file. Changing the basicConfig() call to set the
level to 'level.DEBUG' shows both messages on the console, and only the
first in the file, which is what I did expect.
I suspect my confusion is the distinction between "handler" and
"logger". It appears that the logger won't pass any messages lower than
its level to any of its handlers. If I read the docs, what I need is to
do is have the root logger left at NOTSET, but then there doesn't seem
to be any way to set the level on the default stream handler.
Have I diagnosed the problem correctly? Is the only (or at least,
correct) solution to ignore the default handler and create my own
console and file handlers, setting levels as desired?
The irony is that Bill Gates claims to be making a stable operating
system and Linus Torvalds claims to be trying to take over the
world. -- seen on the net
More information about the Python-list