#!/usr/bin/env python # coding=utf-8 import os folder_path = 'E:\\Desktop' output_file = 'E:\\Desktop\\bsvc_error.log' def merge_files(folder_path, output_file): with open(output_file, 'w', encoding='utf-8') as f: for root, dirs, files in os.walk(folder_path): for file in files: file_path = os.path.join(root, file) with open(file_path, 'r', encoding='utf-8') as f2: content = f2.read() f.write(content) def find_error_log(log_name=output_file): original_file = open(log_name, encoding='utf-8') extract = [] log = [] for line_data in original_file: if '] ERROR' in line_data and 'Token失效,请重新登录' not in line_data: result = line_data[line_data.index("] ERROR") + 8:] extract.append(result) for i in extract: if i not in log: log.append(i) f = open("E:\\Desktop\\test.log", "w") for line in log: f.write(line) f.close() if __name__ == '__main__': merge_files(folder_path, output_file) find_error_log()
标签:log,tomcat,报错,file,output,path,日志,data,line From: https://www.cnblogs.com/teangtang/p/18193902