python简单日志器代码

2022年1月10日10:25:41 发表评论 1,573 views

python 的一个日志器备忘

logger = logging.getLogger("%s_name"%__name__)
logger.setLevel(logging.DEBUG)
fh = logging.FileHandler('RuiNeng.log','a+',encoding='utf-8')
fh.setLevel(logging.DEBUG)
stream = logging.StreamHandler()
stream.setLevel(logging.DEBUG)
format=logging.Formatter('%(asctime)s-%(levelname)s-%(message)s')
fh.setFormatter(format)
stream.setFormatter(format)
logger.addHandler(fh)
logger.addHandler(stream)

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: