#encoding= utf-8 import time from functools import wraps from loguru import logger logger.add("log1.log", filter=lambda record: record["extra"].get("name") == "a",enqueue=True,catch=True) logger.add("log2.log", filter=lambda record: record["extra"].get("name") == "b") logger_a = logger.bind(name="a") logger_b = logger.bind(name="b") def save_print_to_log(act_def): @wraps(act_def) def wrapper(*args, **kwargs): temp_info = act_def( *args, **kwargs) logger_b.info(f'''{act_def.__name__},{temp_info}''') return temp_info return wrapper @save_print_to_log def print_time(): nowtime=time.strftime('%Y-%m-%d') return nowtime if __name__ == '__main__': print(print_time()) logger_a.info("Message c132") logger_b.info("Message B") logger_a.info('142141413')
标签:info,__,name,loguru,写入,print,日志,logger,def From: https://www.cnblogs.com/Monkey18/p/17528048.html