import logging fmt = "%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s: %(message)s" logging.basicConfig( level=logging.DEBUG, format=fmt, filename="D:\logs-220817.txt", filemode="w", datefmt="%a, %d %b %Y %H:%M:%S" ) logging.debug("this is debug logger") logging.info("this is info logger") logging.warn("this is warn logger") logging.error("this is error logger") logging.critical("this is critical logger") # console输出 # WARNING:root:this is warn logger # ERROR:root:this is error logger # CRITICAL:root:this is critical logger # 文件输出 # Wed, 17 Aug 2022 18:59:23 testlogger.py[line:13] DEBUG: this is debug logger # Wed, 17 Aug 2022 18:59:23 testlogger.py[line:14] INFO: this is info logger # Wed, 17 Aug 2022 18:59:23 testlogger.py[line:16] WARNING: this is warn logger # Wed, 17 Aug 2022 18:59:23 testlogger.py[line:17] ERROR: this is error logger # Wed, 17 Aug 2022 18:59:23 testlogger.py[line:18] CRITICAL: this is critical logger
标签:line,logging,Aug,17,python,18,写入,日志,logger From: https://www.cnblogs.com/oktokeep/p/16596457.html