一、日志类的创建
"""
====
#Soft_ware:RiseProject1
#User:cazhong
#Date:22/07/2022
#Time:16:30
=========
"""
import logging,datetime
from logging import Logger
class MyLogger(Logger): # 新建一个日志类(日志收集器)继承原来日志框架的Logger类
def __init__(self,name,level = logging.DEBUG,file = None):
# 1.设置日志的名字、日志收集器的级别
super().__init__(name,level) # 覆盖父类的自带方法(日志收集器)
# 2.可以将日志输出到文件或控制台
fmt = '%(asctime)s - %(filename)s[line:%(lineno)d]: %(message)s'
formatter = logging.Formatter(fmt)
# handler1 = logging.StreamHandler()
# handler1.setFormatter(formatter)
# self.addHandler(handler1) # 渠道绑定在当前日志收集器上面
if file: # 如果文件存在
handler2 = logging.FileHandler(