我是这么使用的log = logging.getLogger()def init_logging():formatter = logging.Formatter("%(asctime)s [%(funcName)s] %(levelname)s: %(message)s")ch = logging.StreamHandler()ch.setFormatter(formatter)log.addHandler(ch)log.setLevel(logging.INFO)log.info("test")然而应该是导入的库里面也有初始化和调用logging,输出日志的时候不仅会输出导入库里面的日志,有些自己的日志还会输出双份
2 回答
喵喵时光机
TA贡献1846条经验 获得超7个赞
把init_logging改为:
def init_logging(): ch = logging.StreamHandler() ch.setLevel(logging.INFO) formatter = logging.Formatter( "%(asctime)s [%(funcName)s] %(levelname)s: %(message)s" ) ch.setFormatter(formatter) logging.getLogger('').addHandler(ch) |
添加回答
举报
0/150
提交
取消