Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么';t Python logger在logging.info级别显示信息或调试消息?_Python_Logging - Fatal编程技术网

为什么';t Python logger在logging.info级别显示信息或调试消息?

为什么';t Python logger在logging.info级别显示信息或调试消息?,python,logging,Python,Logging,有人能给我解释一下为什么.info()和.debug()调用不打印任何东西,即使它们看起来应该打印什么?我觉得有一些非常基本的东西我不理解,即使在阅读了日志模块文档之后 $ python Python 3.6.5 (default, Apr 25 2018, 14:23:58) [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwin Typ

有人能给我解释一下为什么.info()和.debug()调用不打印任何东西,即使它们看起来应该打印什么?我觉得有一些非常基本的东西我不理解,即使在阅读了日志模块文档之后

$  python                                    
Python 3.6.5 (default, Apr 25 2018, 14:23:58) 
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logger = logging.getLogger()
>>> logger.setLevel(logging.INFO)
>>> logger.warning('This is a warning. We should see it.')
This is a warning. We should see it.
>>> logger.debug('This is a debug message. We should not see it.')
>>> logger.info('This is an info message. We should... see it, right?')
>>> logger.setLevel(logging.DEBUG)
>>> logger.info('This is an info message. We should... see it, right?')
>>> logger.debug('Weird. So I guess we are not going to see this as well?')
>>> 

这是记录,只是不到终端。如果要查看输出到终端的日志(非常类似于打印),则需要添加一个处理程序:

logger.addHandler(logging.StreamHandler())

执行此操作后,日志应按预期显示到您的终端。

它是日志,而不是显示到终端。如果要查看输出到终端的日志(非常类似于打印),则需要添加一个处理程序:

logger.addHandler(logging.StreamHandler())
完成此操作后,日志应按预期显示在终端上