From f2317c781686254c5926df49bee7e110965d2793 Mon Sep 17 00:00:00 2001 From: Dyna <108321411+Ahaohaohao@users.noreply.github.com> Date: Tue, 15 Jul 2025 18:55:53 +0800 Subject: [PATCH] fix: log levels will not display their respective logs correctly (#4074) * fix-log levels will not display their respective logs correctly * fix-logs * Update UPDATELOG.md * Update UPDATELOG.md --- UPDATELOG.md | 1 + src/pages/logs.tsx | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/UPDATELOG.md b/UPDATELOG.md index f7c1d5cd..24b4ba45 100644 --- a/UPDATELOG.md +++ b/UPDATELOG.md @@ -14,6 +14,7 @@ - 修复`DNS`覆写 `nameserver-policy` 字段无法正确识别 `geo` 库 - 修复搜索框输入特殊字符崩溃 - 修复 Windows 下 Start UP 名称与 exe 名称不统一 +- 修复显示 Mihomo 内核日志等级应该大于设置等级 ### ✨ 新增功能 diff --git a/src/pages/logs.tsx b/src/pages/logs.tsx index 8fedd052..0b4778dc 100644 --- a/src/pages/logs.tsx +++ b/src/pages/logs.tsx @@ -24,6 +24,15 @@ import { toggleLogEnabled, } from "@/services/global-log-service"; +// 定义日志级别结构 +const LOG_LEVEL_HIERARCHY = { + all: ["info", "warning", "error", "debug"], + info: ["info", "warning", "error"], + warning: ["warning", "error"], + error: ["error"], + debug: ["debug"], +}; + const LogPage = () => { const { t } = useTranslation(); const [enableLog, setEnableLog] = useEnableLog(); @@ -35,21 +44,29 @@ const LogPage = () => { "info", ); const [match, setMatch] = useState(() => (_: string) => true); - const logData = useGlobalLogData(logLevel); + const logData = useGlobalLogData("all"); const [searchState, setSearchState] = useState(); const filterLogs = useMemo(() => { - return logData - ? logData.filter((data) => { - // 构建完整的搜索文本,包含时间、类型和内容 - const searchText = - `${data.time || ""} ${data.type} ${data.payload}`.toLowerCase(); + if (!logData || logData.length === 0) { + return []; + } - return logLevel === "all" - ? match(searchText) - : data.type.toLowerCase() === logLevel && match(searchText); - }) - : []; + const allowedTypes = LOG_LEVEL_HIERARCHY[logLevel] || []; + + return logData.filter((data) => { + const logType = data.type?.toLowerCase() || ""; + const isAllowedType = + logLevel === "all" || allowedTypes.includes(logType); + + // 构建完整的搜索文本,包含时间、类型和内容 + const searchText = + `${data.time || ""} ${data.type} ${data.payload}`.toLowerCase(); + + const matchesSearch = match(searchText); + + return isAllowedType && matchesSearch; + }); }, [logData, logLevel, match]); const handleLogLevelChange = (newLevel: LogLevel) => {