Where is this logging to?

2019-02-28 18:16发布

I have this python code:

import logging
LOGGER = logging.getLogger(__name__)
LOGGER.info('test')

It does not get written to the console, so where does this get logged?

1条回答
相关推荐>>
2楼-- · 2019-02-28 18:49

This does not get logged anywhere, because you did not configure any logging handlers. Without a handler configured, the log event goes nowhere. When there are no handlers configured, the root logger gets a handler automatically added if an event at WARNING or above is seen, but your event was just at INFO level.

If you put a line like this before, then you will see it logged to terminal:

logging.basicConfig(level=logging.INFO)

Basic config will add a StreamHandler writing to sys.stderr if you don't specify otherwise.

查看更多
登录 后发表回答