Python logging.info()不记录消息 [英] Python logging.info() not logging the message
本文介绍了Python logging.info()不记录消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
parser_logger = logging.getLogger("CSHEL_parserlogger");
#logging.basicConfig()
parser_logger.addHandler(RotatingFileHandler(
"logfile", mode='a', maxBytes=7340032, backupCount=4,
encoding=None, delay=False))
#d = { 'clientip' : '192.168.0.1', 'user' : 'fbloggs' }
parser_logger.info('Protocol problem: %s', 'connection reset')
这将创建一个名为logfile的文件,但不会在其中写入任何内容. 如果我将最后一行更改为
This would create a file named logfile, but won't write anything into it. If I change the last line to
parser_logger.warning('Protocol problem: %s', 'connection reset')
它将正确地将消息记录到日志文件"中.
it would log the message into the "logfile" properly.
我确定这是我想念的一件小事,但我无法弄清楚它是什么.
I am sure it's a petty thing that I am missing, but I am not able to figure out what it is.
推荐答案
您需要设置记录器的阈值级别:
You need to set the threshold level of the logger:
parser_logger.setLevel(logging.INFO)
创建记录器时,级别设置为NOTSET
,并且根记录器的创建级别为WARNING
.参见文档.
When a logger is created, the level is set to NOTSET
, and the root logger is created with level WARNING
. See the documentation.
这篇关于Python logging.info()不记录消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文