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:
@@ -14,6 +14,7 @@
|
||||
- 修复`DNS`覆写 `nameserver-policy` 字段无法正确识别 `geo` 库
|
||||
- 修复搜索框输入特殊字符崩溃
|
||||
- 修复 Windows 下 Start UP 名称与 exe 名称不统一
|
||||
- 修复显示 Mihomo 内核日志等级应该大于设置等级
|
||||
|
||||
### ✨ 新增功能
|
||||
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user