https://www.cnblogs.com/tastepy/p/13328847.html
在网上找了好久,最后在上面的链接中,找到了解决方案
import logging def get_logger(logger_name,log_file,level=logging.INFO): logger = logging.getLogger(logger_name) formatter = logging.Formatter('%(asctime)s : %(message)s', "%Y-%m-%d %H:%M:%S") fileHandler = logging.FileHandler(log_file, mode='a') fileHandler.setFormatter(formatter) logger.setLevel(level) logger.addHandler(fileHandler) return logger log_file1 = 'file1.log' log_file2 = 'file2.log' log1 = get_logger('log1',log_file1) log2 = get_logger('log2', log_file2)
log1.error('错误消息') log2.info('信息')