feat(audit): 平滑升级-监听器+装饰器共存,装饰器自动检测并跳过已处理日志
This commit is contained in:
@ -301,6 +301,22 @@ def audit_log(module: str, action: str = None, get_target_id_fn=None, get_target
|
||||
# 默认:记录请求 Payload
|
||||
details = {'payload': filtered_payload}
|
||||
|
||||
# ★ 关键:检查是否已被底层监听器处理
|
||||
# 如果底层已生成高级日志(changes/deleted_snapshot),则跳过简单的 payload 日志
|
||||
from flask import g, has_request_context
|
||||
if has_request_context() and hasattr(g, 'audit_handled_ids') and g.audit_handled_ids:
|
||||
# 构建检查 key: "module:target_id"
|
||||
check_key = f"{module}:{target_id}" if target_id else None
|
||||
if check_key and check_key in g.audit_handled_ids:
|
||||
# 底层已处理,跳过装饰器日志
|
||||
current_app.logger.info(f'[审计] 底层监听器已处理 {check_key},跳过装饰器')
|
||||
return response
|
||||
# 也检查 target_name 是否匹配
|
||||
for key in g.audit_handled_ids:
|
||||
if target_name and target_name in key:
|
||||
current_app.logger.info(f'[审计] 底层监听器已处理 {key},跳过装饰器')
|
||||
return response
|
||||
|
||||
# 保存日志
|
||||
log_entry = AuditLog(
|
||||
user_id=user_id,
|
||||
|
||||
Reference in New Issue
Block a user