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

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

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