The basics of the logging module mystify me

Skip Montanaro skip.montanaro at gmail.com
Wed Apr 18 21:00:48 EDT 2018


This session is from Python 3.6.5 on Linux:

>>> import logging
>>> log = logging.getLogger()
>>> log.level
30
>>> logging.WARN
30
>>> log.warn("Awk! Goodbye...")
Awk! Goodbye...
>>> log.level = logging.INFO
>>> log.info("Awk! Goodbye...")
>>> log.level
20
>>> log.level == logging.INFO
True
>>> log.setLevel(logging.INFO)
>>> log.info("Awk! Goodbye...")
>>> log.isEnabledFor(logging.INFO)
True

Why do the two log.info(...) calls not produce output on stderr when
the level has clearly been set to logging.INFO? There is an active
stream handler as demonstrated by the successful log.warn(...) call.

I really don't like the logging module, but it looks like I'm stuck
with it. Why aren't simple/obvious things either simple or obvious?

Skip



More information about the Python-list mailing list