为什么不将日志记录信息打印到屏幕上?

时间:2019-06-19 21:27:36

标签: python

我正在使用PyCharm,并想测试日志记录:

import logging


logging.info("This is the logging info ...")

我想这应该在我运行程序时在控制台上打印出“这是日志记录信息...”,但是没有。

我在登录时没有任何其他设置或配置。日志信息会去哪里?

2 个答案:

答案 0 :(得分:0)

您需要配置记录器,为其提供输出文件和所有内容

logging.info(msg, *args, **kwargs)
Logs a message with level INFO on the root logger. The arguments are interpreted as for debug().

更多信息可以在这里找到:https://docs.python.org/3/howto/logging-cookbook.html

答案 1 :(得分:0)

根记录器的默认级别为WARNING。您需要先配置记录器以更改其级别。例如,

import logging

logging.basicConfig(level=logging.INFO)
logging.info("This is the logging info ...")