osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

The basics of the logging module mystify me


On Thu, Apr 19, 2018 at 11:00 AM, Skip Montanaro
<skip.montanaro at gmail.com> wrote:
> 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?

I've no idea what setting log.level does; I would normally use
logging.basicConfig to set that sort of thing.

logging.basicConfig(level=logging.INFO)

ChrisA