Logger vs. Handler log levels
steveg at moregruel.net
Fri Jun 22 04:30:05 CEST 2007
According to John J. Lee <jjl at pobox.com>:
> steveg at moregruel.net (Steve Greenland) writes:
> > import logging, logging.handlers
> > logging.basicConfig(level=logging.WARNING)
> > newlog = logging.handlers.TimedRotatingFileHandler(
> > filename='/home/steveg/logtest.log',
> > when="midnight")
> > newlog.setLevel(logging.INFO)
> > logging.getLogger().addHandler(newlog)
> > 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.
> Not sure why you'd expect to see console output regardless of the
> logger / handler issue -- INFO and DEBUG are lower in priority than
> WARNING, and you've set the (logger) level to WARNING with the
> logging.basicConfig() call (indicating you're only interested in
> things at least that serious, not mere INFOrmational messages).
Yes, that's why I added "(as expected)" :-) Oh, duh, I see, it can be
parsed to mean the opposite of what I intended. What I meant was "As
expected, there was no console output."
Anyway, thanks for your confirmations.
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