记录一下tomcat报错日志分析(去重分类)

#!/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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值