Toggle navigation
Toggle navigation
This project
Loading...
Sign in
万朱浩
/
Venue-Ops
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
马一丁
2025-12-04 15:29:00 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
25abc25c9dcf2c2a8b4e0ccd4b6e38ba9c173280
25abc25c
1 parent
ec1baf53
Update Report Engine Log Filtering Strategy
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
1 deletions
ReportEngine/agent.py
ReportEngine/flask_interface.py
ReportEngine/agent.py
View file @
25abc25
...
...
@@ -245,6 +245,31 @@ class ReportAgent:
log_dir
=
os
.
path
.
dirname
(
self
.
config
.
LOG_FILE
)
os
.
makedirs
(
log_dir
,
exist_ok
=
True
)
def
_exclude_other_engines
(
record
):
"""
过滤掉其他引擎(Insight/Media/Query/Forum)产生的日志,其余日志全部保留。
使用路径匹配为主,无法获取路径时退化到模块名。
"""
excluded_keywords
=
(
"InsightEngine"
,
"MediaEngine"
,
"QueryEngine"
,
"ForumEngine"
)
try
:
file_path
=
record
[
"file"
]
.
path
if
any
(
keyword
in
file_path
for
keyword
in
excluded_keywords
):
return
False
except
Exception
:
pass
try
:
module_name
=
record
.
get
(
"module"
,
""
)
if
isinstance
(
module_name
,
str
):
lowered
=
module_name
.
lower
()
if
any
(
keyword
.
lower
()
in
lowered
for
keyword
in
excluded_keywords
):
return
False
except
Exception
:
pass
return
True
# 【修复】检查是否已经添加过这个文件的handler,避免重复
# loguru会自动去重,但显式检查更安全
log_file_path
=
str
(
Path
(
self
.
config
.
LOG_FILE
)
.
resolve
())
...
...
@@ -274,7 +299,8 @@ class ReportAgent:
buffering
=
1
,
# 行缓冲,每行立即写入
serialize
=
False
,
# 普通文本格式,不序列化为JSON
encoding
=
"utf-8"
,
# 明确UTF-8编码
mode
=
"a"
# 追加模式
mode
=
"a"
,
# 追加模式
filter
=
_exclude_other_engines
# 过滤掉四个 Engine 的日志,保留其余信息
)
logger
.
debug
(
f
"已添加日志handler (ID: {handler_id}): {self.config.LOG_FILE}"
)
...
...
ReportEngine/flask_interface.py
View file @
25abc25
...
...
@@ -42,6 +42,33 @@ tasks_registry: Dict[str, 'ReportTask'] = {}
LOG_STREAM_LEVELS
=
{
"DEBUG"
,
"INFO"
,
"WARNING"
,
"ERROR"
,
"CRITICAL"
}
log_stream_handler_id
:
Optional
[
int
]
=
None
EXCLUDED_ENGINE_PATH_KEYWORDS
=
(
"ForumEngine"
,
"InsightEngine"
,
"MediaEngine"
,
"QueryEngine"
)
def
_is_excluded_engine_log
(
record
:
Dict
[
str
,
Any
])
->
bool
:
"""
判断日志是否来自其他引擎(Insight/Media/Query/Forum),用于过滤混入的日志。
返回:
bool: True 表示应当过滤(即不写入/不转发)。
"""
try
:
file_path
=
record
[
"file"
]
.
path
if
any
(
keyword
in
file_path
for
keyword
in
EXCLUDED_ENGINE_PATH_KEYWORDS
):
return
True
except
Exception
:
pass
# 兜底:尝试按模块名过滤,防止file信息缺失时误混入
try
:
module_name
=
record
.
get
(
"module"
,
""
)
if
isinstance
(
module_name
,
str
):
lowered
=
module_name
.
lower
()
return
any
(
keyword
.
lower
()
in
lowered
for
keyword
in
EXCLUDED_ENGINE_PATH_KEYWORDS
)
except
Exception
:
pass
return
False
def
_stream_log_to_task
(
message
):
"""
...
...
@@ -54,6 +81,8 @@ def _stream_log_to_task(message):
level_name
=
record
[
"level"
]
.
name
if
level_name
not
in
LOG_STREAM_LEVELS
:
return
if
_is_excluded_engine_log
(
record
):
return
with
task_lock
:
task
=
current_task
...
...
Please
register
or
login
to post a comment