日志模块:
import logging import os def creat_log(name="mylog", level="DEBUG", filename="log.log", sh_level="DEBUG", fh_level="DEBUG"): log = logging.getLogger(name) log.setLevel(level) fh = logging.FileHandler(filename, encoding="utf-8") fh.setLevel(sh_level) log.addHandler(fh) sh = logging.StreamHandler() sh.setLevel("DEBUG") log.addHandler(sh) formats = "%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s" log_format = logging.Formatter(formats) fh.setFormatter(log_format) sh.setFormatter(log_format) return log my_log = creat_log()
其他模块如何引入日志模块:
from hander_log import my_log my_log.error("hao") my_log.debug("buhao")
123
标签:封装,log,level,python,DEBUG,sh,自动化,fh,logging From: https://www.cnblogs.com/xiaobaibailongma/p/18082608