#!/usr/bin/env python
# coding=utf-8
import os
folder_path = 'E:\\Desktop'
output_file = 'E:\\Desktop\\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()
记录一下tomcat报错日志分析(去重分类)
最新推荐文章于 2026-03-30 09:43:34 发布
&spm=1001.2101.3001.5002&articleId=138909198&d=1&t=3&u=1fe31ee47c69427a8f1fa78002eecf94)
2599

被折叠的 条评论
为什么被折叠?



