python logging 默认级别_python的logging日志级别设置不生效

  • Post author:
  • Post category:python


import logging

from logging.handlers import RotatingFileHandler

log_file = “log/log”

datetime_format = “%Y-%m-%d %H:%M:%S”

per_log_file_max_size = 10240

backup_count = 3

log_format = “%(asctime)s %(filename)sline:%(lineno)d %(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’)

输出:

2017-02-10 18:00:26,408 test.pyline:32 This is warning message

2017-02-10 18:00:26,408 test.pyline:33 error

2017-02-10 18:00:26,408 test.pyline:34 critical

设置的日志级别是NOSET,实际上是WARNING

求解释:



版权声明:本文为weixin_34875640原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。