Pythonlogging.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 的文件,但不会向其中写入任何内容。 如果我更改最后一行,
parser_logger.warning('Protocol problem: %s', 'connection reset')
它将正确地将消息记录到“日志文件”中。
我确信我错过了一件小事,但我无法弄清楚它是什么。
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')
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要设置记录器的阈值级别:
创建记录器时,级别设置为
NOTSET
,并且创建根记录器的级别为WARNING
。请参阅文档。You need to set the threshold level of the logger:
When a logger is created, the level is set to
NOTSET
, and the root logger is created with levelWARNING
. See the documentation.