1、loguru 如果有需要做打印多份的情况,可以使用 filter 参数来筛选打印的内容
logger.add(self.can_log_add, rotation="5 MB", encoding='utf-8', filter=lambda x: '[CAN]' in x['message'])
class MyLogger:
def __init__(self, path, case_name):
self.can_log_add = path + "\\" + case_name + "_报文.log"
self.can_log_add1 = path + "\\" + case_name + "_错误报文.log"
logger.add(self.can_log_add, rotation="5 MB",
encoding='utf-8', filter=lambda x: '[CAN]' in x['message'])
logger.add(self.can_log_add1 , rotation="5 MB",
encoding='utf-8', filter=lambda x: '[错误的log]' in x['message'])
def log_info(self, info_txt):
logger.info(info_txt)
如果喜欢,点赞关注哦!