fix: can not filiter log level as expected

This commit is contained in:
Tunglies
2025-08-03 09:52:27 +08:00
parent 3eb2a5b3ef
commit d16c691c0f
10 changed files with 83 additions and 44 deletions

View File

@@ -420,6 +420,10 @@ export async function startLogsMonitoring(level?: string) {
return invoke<void>("start_logs_monitoring", { level });
}
export async function stopLogsMonitoring() {
return invoke<void>("stop_logs_monitoring");
}
export async function clearLogs() {
return invoke<void>("clear_logs");
}

View File

@@ -3,6 +3,7 @@ import { create } from "zustand";
import {
fetchLogsViaIPC,
startLogsStreaming,
stopLogsStreaming,
clearLogs as clearLogsIPC,
} from "@/services/ipc-log-service";
import dayjs from "dayjs";
@@ -123,12 +124,21 @@ const clearIpcPolling = () => {
}
};
// 关闭全局日志连接 (仅IPC模式)
export const closeGlobalLogConnection = () => {
// 停止日志监控 (仅IPC模式)
export const stopGlobalLogMonitoring = async () => {
clearIpcPolling();
isInitializing = false; // 重置初始化标志
// 调用后端停止监控
await stopLogsStreaming();
useGlobalLogStore.setState({ isConnected: false });
console.log("[GlobalLog-IPC] 日志服务已关闭");
console.log("[GlobalLog-IPC] 日志监控已停止");
};
// 关闭全局日志连接 (仅IPC模式) - 保持向后兼容
export const closeGlobalLogConnection = async () => {
await stopGlobalLogMonitoring();
};
// 切换日志级别 (仅IPC模式)
@@ -150,7 +160,7 @@ export const changeLogLevel = (level: LogLevel) => {
};
// 切换启用状态 (仅IPC模式)
export const toggleLogEnabled = () => {
export const toggleLogEnabled = async () => {
const { enabled, currentLevel } = useGlobalLogStore.getState();
const newEnabled = !enabled;
@@ -160,14 +170,14 @@ export const toggleLogEnabled = () => {
// IPC模式下直接启动
initGlobalLogService(newEnabled, currentLevel);
} else {
closeGlobalLogConnection();
await stopGlobalLogMonitoring();
}
};
// 获取日志清理函数
// 获取日志清理函数 - 只清理前端日志,不停止监控
export const clearGlobalLogs = () => {
useGlobalLogStore.getState().clearLogs();
// 同时清理后端流式缓存
// 同时清理后端缓存的日志,但不停止监控
clearLogsIPC();
};

View File

@@ -2,6 +2,7 @@
import {
getClashLogs,
startLogsMonitoring,
stopLogsMonitoring,
clearLogs as clearLogsCmd,
} from "@/services/cmds";
import dayjs from "dayjs";
@@ -28,6 +29,16 @@ export const startLogsStreaming = async (logLevel: LogLevel = "info") => {
}
};
// Stop logs monitoring
export const stopLogsStreaming = async () => {
try {
await stopLogsMonitoring();
console.log("[IPC-LogService] Stopped logs monitoring");
} catch (error) {
console.error("[IPC-LogService] Failed to stop logs monitoring:", error);
}
};
// Fetch logs using IPC command (now from streaming cache)
export const fetchLogsViaIPC = async (
logLevel: LogLevel = "info",