提交 f8f05df8 authored 作者: 陈泽健's avatar 陈泽健

补充_process_line函数对日志去重的IP过滤,parse_log_line函数增加IP过滤,处理相同错误日志因IP不同识别为不同错误问题。

上级 234b7179
...@@ -17,3 +17,4 @@ ...@@ -17,3 +17,4 @@
- 日志监测服务补充对外云端服务以及展厅统一平台微服务。服务监测补充对外云端以及展厅环境。 - 日志监测服务补充对外云端服务以及展厅统一平台微服务。服务监测补充对外云端以及展厅环境。
- 处理日志文件存放路径问题,文件目录名称被修改引起。处理日志文件存放问题,优化路径。 - 处理日志文件存放路径问题,文件目录名称被修改引起。处理日志文件存放问题,优化路径。
- 补充监测服务的前置ngrok映射以及端口开放的使用指令注释,处理注释错误。 - 补充监测服务的前置ngrok映射以及端口开放的使用指令注释,处理注释错误。
- 补充_process_line函数对日志去重的IP过滤,parse_log_line函数增加IP过滤,处理相同错误日志因IP不同识别为不同错误问题。
\ No newline at end of file
...@@ -214,7 +214,10 @@ class LogMonitor: ...@@ -214,7 +214,10 @@ class LogMonitor:
error_log_url = self.generate_error_log_url(file_path) error_log_url = self.generate_error_log_url(file_path)
# 使用结构化字段做 key # 使用结构化字段做 key
key = f"{parsed['module']}_{parsed['action']}_{parsed['message']}" # 修改后的去重key生成
clean_message = re.sub(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', '[IP]', parsed['message'])
key = f"{parsed['module']}_{parsed['action']}_{clean_message}"
# 打印构造去重key值 # 打印构造去重key值
logging.info(f"构造去重 key: {key}") logging.info(f"构造去重 key: {key}")
error_hash = hash(key) error_hash = hash(key)
...@@ -299,33 +302,26 @@ class LogMonitor: ...@@ -299,33 +302,26 @@ class LogMonitor:
def parse_log_line(self, line): def parse_log_line(self, line):
logging.info(f"正在处理的日志行: {line}") logging.info(f"正在处理的日志行: {line}")
logging.info(f"repr格式: {repr(line)}")
# 原有匹配逻辑
timestamp_match = re.match(r'^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+)', line) timestamp_match = re.match(r'^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d+)', line)
level_match = re.search(r'\s(ERROR|INFO|WARNING)\b', line) # 扩展支持更多日志级别 level_match = re.search(r'\s(ERROR|INFO|WARNING)\b', line)
if not timestamp_match or not level_match:
return None
# 修改后的正则表达式:同时匹配中文【】和英文[]括号
bracket_content = re.findall(r'\[(.*?)\]|\【(.*?)\】', line) bracket_content = re.findall(r'\[(.*?)\]|\【(.*?)\】', line)
bracket_content = [x[0] or x[1] for x in bracket_content if x[0] or x[1]] bracket_content = [x[0] or x[1] for x in bracket_content if x[0] or x[1]]
logging.info(f"提取到的内容: {bracket_content}") if not timestamp_match or not level_match or len(bracket_content) < 3:
if len(bracket_content) < 3:
return None return None
module = bracket_content[0].strip() # IP过滤函数
action = bracket_content[1].strip() def remove_ip(text):
message = bracket_content[2].strip() return re.sub(r'\d{1,3}\\.\d{1,3}\\.\d{1,3}\\.\d{1,3}', '[IP]', text)
return { return {
'level': level_match.group(1).strip(), 'level': level_match.group(1).strip(),
'module': module, 'module': remove_ip(bracket_content[0].strip()),
'action': action, 'action': remove_ip(bracket_content[1].strip()),
'message': message, 'message': remove_ip(bracket_content[2].strip()),
'raw': line.strip() 'raw': line.strip() # 保留原始信息
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论