为了账号安全,请及时绑定邮箱和手机立即绑定

困惑:定义的日志级别是NOSET,实际是WANING ?求解释

困惑:定义的日志级别是NOSET,实际是WANING ?求解释

繁星点点滴滴 2023-03-19 13:09:06
log_file = "log/log"datetime_format = "%Y-%m-%d %H:%M:%S"per_log_file_max_size = 10240backup_count = 3log_format = "%(asctime)s %(filename)s[line:%(lineno)d][%(levelname)s] %(message)s"rotate_file_handler = RotatingFileHandler(log_file, maxBytes=per_log_file_max_size,backupCount=backup_count)rotate_file_handler.setLevel(logging.NOTSET)formatter = logging.Formatter(log_format)rotate_file_handler.setFormatter(formatter)logging.getLogger('').addHandler(rotate_file_handler)logging.debug('This is debug message')logging.info('This is info message')logging.warning('This is warning message')logging.error('error')logging.critical('critical')输出:2017-02-10 17:43:29,055 test.py[line:31][WARNING] This is warning message2017-02-10 17:43:29,055 test.py[line:32][ERROR] error2017-02-10 17:43:29,055 test.py[line:33][CRITICAL] critical
查看完整描述

1 回答

?
RISEBY

TA贡献1856条经验 获得超5个赞

log_format = "%(asctime)s %(filename)s[line:%(lineno)d][%(levelname)s] %(message)s"logging.basicConfig(format=log_format,level='ERROR')logging.debug('This is debug message')logging.info('This is info message')logging.warning('This is warning message')logging.error('error')logging.critical('critical')



查看完整回答
反对 回复 2023-03-21
  • 1 回答
  • 0 关注
  • 57 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信