logging.getLogger('name')。setLevel()似乎不起作用

时间:2019-09-12 11:36:58

标签: python logging

我在这里有示例代码,试图将默认的记录器级别设置为info,尽管对象说它的级别是info,但从logger.info()仍然无法得到任何信息

运行python3.6:

import logging
a = logging.getLogger('a')
a.info('bla') # should be ignored as a's level is warning
a.warning('bla')
a.setLevel('INFO')
a.info('bla') # should now work, but still nothing is shown...

从iPython运行:

In [1]: import logging 
   ...: a = logging.getLogger('a') 
   ...: a                                                                                                                                                                                    
Out[1]: <Logger a (WARNING)>
In [2]: a.info('bla') # should be ignored as a's level is warning                                                                                                                            
In [3]: a.warning('bla')                                                                                                                                                                     
bla
In [4]: a.setLevel('INFO')                                                                                                                                                                   
# nothing
In [5]: a                                                                                                                                                                                    
Out[5]: <Logger a (INFO)>
In [6]: a.info('bla') # should now work, but still nothing is shown...                                                                                                                       
# **still nothing...**

0 个答案:

没有答案