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
This commit is contained in:
Dyna
2025-07-15 18:55:53 +08:00
committed by GitHub
Unverified
parent 7fce7ca62f
commit f2317c7816
2 changed files with 29 additions and 11 deletions

View File

@@ -14,6 +14,7 @@
- 修复`DNS`覆写 `nameserver-policy` 字段无法正确识别 `geo`
- 修复搜索框输入特殊字符崩溃
- 修复 Windows 下 Start UP 名称与 exe 名称不统一
- 修复显示 Mihomo 内核日志等级应该大于设置等级
### ✨ 新增功能

View File

@@ -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<SearchState>();
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) => {