我是這么使用的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")然而應(yīng)該是導(dǎo)入的庫(kù)里面也有初始化和調(diào)用logging,輸出日志的時(shí)候不僅會(huì)輸出導(dǎo)入庫(kù)里面的日志,有些自己的日志還會(huì)輸出雙份
2 回答

喵喵時(shí)光機(jī)
TA貢獻(xiàn)1846條經(jīng)驗(yàn) 獲得超7個(gè)贊
把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) |
添加回答
舉報(bào)
0/150
提交
取消