Logger not logging

Peter Otten __peter__ at web.de
Thu Jan 1 18:59:42 CET 2015


Jason Friedman wrote:


> I expect logger.info("hello") to emit.
> 
> $ python
> Python 3.4.0 (default, Apr 18 2014, 19:16:28)
> [GCC 4.8.1] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import logging
>>>> logger = logging.getLogger()
>>>> logger.setLevel(logging.INFO)
>>>> logger.info("hello")
>>>> logger.warn("hello")
> hello
>>>>

> What am I missing?

The handler also filters. The easiest way to get one that is configured 
appropriately is to use basicConfig():

>>> import logging
>>> logging.basicConfig(level=logging.INFO)
>>> root = logging.getLogger()
>>> root.info("hello")
INFO:root:hello





More information about the Python-list mailing list