feat: Introduce unified logging system and optimize file management
- Added a new unified logging module to standardize log formatting, including support for traceId and MDC for better tracking. - Updated `.gitignore` to exclude code analysis reports and temporary files. - Created cleanup scripts to manage unused files and generate cleanup reports. - Enhanced existing modules to integrate the new logging system and improve debugging capabilities. - Removed outdated files and scripts to streamline the project structure.
This commit is contained in:
1 parent
08a0b41834
commit
e5a510d19b
45 files changed
+18285
-1357
No files matched your search
+37
-1
@@ -255,7 +255,30 @@ class ProcRunner:
|
||||
if not s:
|
||||
return
|
||||
|
||||
# --- 福袋:抽取“最近一次”识别到的信息 ---
|
||||
# --- 统一日志格式解析:提取traceId和MDC信息 ---
|
||||
# 格式:时间戳(毫秒) - [级别] - [线程名] - [模块名:函数名:行号] - [traceId:xxx] - 消息 | MDC: 上下文信息
|
||||
trace_id_match = re.search(r'\[traceId:([^\]]+)\]', s)
|
||||
if trace_id_match:
|
||||
trace_id = trace_id_match.group(1)
|
||||
# 存储当前traceId(用于统计和显示)
|
||||
if not hasattr(self, '_current_trace_id'):
|
||||
self._current_trace_id = trace_id
|
||||
elif trace_id != 'N/A':
|
||||
self._current_trace_id = trace_id
|
||||
|
||||
# 提取MDC信息
|
||||
mdc_match = re.search(r'MDC:\s*([^|]+)', s)
|
||||
if mdc_match:
|
||||
mdc_str = mdc_match.group(1).strip()
|
||||
# 解析MDC键值对
|
||||
mdc_pairs = re.findall(r'(\w+)=([^,\s]+)', mdc_str)
|
||||
for key, value in mdc_pairs:
|
||||
# 存储MDC信息(可用于统计)
|
||||
if not hasattr(self, '_mdc_context'):
|
||||
self._mdc_context = {}
|
||||
self._mdc_context[key] = value
|
||||
|
||||
# --- 福袋:抽取"最近一次"识别到的信息 ---
|
||||
if "福袋内容:" in s:
|
||||
self._fudai_last["content"] = s.split("福袋内容:", 1)[1].strip()
|
||||
self._fudai_last["updated_ts"] = time.time()
|
||||
@@ -655,6 +678,14 @@ class ProcRunner:
|
||||
"timeline": timeline,
|
||||
}
|
||||
|
||||
# 获取当前traceId和MDC上下文
|
||||
current_trace_id = getattr(self, '_current_trace_id', None)
|
||||
mdc_context = dict(getattr(self, '_mdc_context', {}))
|
||||
|
||||
# 获取当前traceId和MDC上下文
|
||||
current_trace_id = getattr(self, '_current_trace_id', None)
|
||||
mdc_context = dict(getattr(self, '_mdc_context', {}))
|
||||
|
||||
payload = {
|
||||
"running": bool(running),
|
||||
"pid": pid,
|
||||
@@ -670,6 +701,11 @@ class ProcRunner:
|
||||
"agg": agg,
|
||||
# 仅返回最近 20 条,避免过大
|
||||
"wins": wins[-20:],
|
||||
# 统一日志系统信息
|
||||
"trace_id": current_trace_id,
|
||||
"mdc_context": mdc_context,
|
||||
"trace_id": current_trace_id,
|
||||
"mdc_context": mdc_context,
|
||||
}
|
||||
|
||||
if include_events:
|
||||
|
||||
Reference in new issue
Block a user