mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
fix: can not filiter log level as expected
This commit is contained in:
@@ -45,7 +45,7 @@
|
|||||||
- 修复 `Windows` 安装器参数使用错误问题
|
- 修复 `Windows` 安装器参数使用错误问题
|
||||||
- 修复 `IPC` 迁移后节点测速功能异常
|
- 修复 `IPC` 迁移后节点测速功能异常
|
||||||
- 修复 `IPC` 迁移后连接上下行速率计算功能异常
|
- 修复 `IPC` 迁移后连接上下行速率计算功能异常
|
||||||
- 修复 `IPC` 迁移后内核日志功能异常
|
- 修复 `IPC` 迁移后内核日志(等级切换)功能异常
|
||||||
- 修复 `External-Controller-Cors` 无法保存所需前置条件
|
- 修复 `External-Controller-Cors` 无法保存所需前置条件
|
||||||
- 修复首页端口不一致问题
|
- 修复首页端口不一致问题
|
||||||
- 修复首页流量统计卡片重构后无法显示流量刻度线
|
- 修复首页流量统计卡片重构后无法显示流量刻度线
|
||||||
|
|||||||
@@ -591,6 +591,13 @@ pub async fn start_logs_monitoring(level: Option<String>) -> CmdResult {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 停止日志监控
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn stop_logs_monitoring() -> CmdResult {
|
||||||
|
ipc::stop_logs_monitoring().await;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// 清除日志
|
/// 清除日志
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn clear_logs() -> CmdResult {
|
pub async fn clear_logs() -> CmdResult {
|
||||||
|
|||||||
@@ -153,16 +153,7 @@ impl LogsMonitor {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let url = if filter_level == "info" {
|
let url = "/logs";
|
||||||
"/logs".to_string()
|
|
||||||
} else {
|
|
||||||
let level_param = if filter_level == "all" {
|
|
||||||
"debug"
|
|
||||||
} else {
|
|
||||||
&filter_level
|
|
||||||
};
|
|
||||||
format!("/logs?level={level_param}")
|
|
||||||
};
|
|
||||||
|
|
||||||
logging!(
|
logging!(
|
||||||
info,
|
info,
|
||||||
@@ -173,7 +164,7 @@ impl LogsMonitor {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let _ = client
|
let _ = client
|
||||||
.get(&url)
|
.get(url)
|
||||||
.timeout(Duration::from_secs(30))
|
.timeout(Duration::from_secs(30))
|
||||||
.process_lines(|line| {
|
.process_lines(|line| {
|
||||||
Self::process_log_line(line, &filter_level, monitor_current.clone())
|
Self::process_log_line(line, &filter_level, monitor_current.clone())
|
||||||
@@ -200,6 +191,28 @@ impl LogsMonitor {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn stop_monitoring(&self) {
|
||||||
|
// Stop monitoring task but keep logs
|
||||||
|
{
|
||||||
|
let mut handle = self.task_handle.write().await;
|
||||||
|
if let Some(task) = handle.take() {
|
||||||
|
task.abort();
|
||||||
|
logging!(
|
||||||
|
info,
|
||||||
|
Type::Ipc,
|
||||||
|
true,
|
||||||
|
"LogsMonitor: Stopped monitoring task"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset monitoring level
|
||||||
|
{
|
||||||
|
let mut monitoring_level = self.current_monitoring_level.write().await;
|
||||||
|
*monitoring_level = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn create_ipc_client() -> Result<
|
async fn create_ipc_client() -> Result<
|
||||||
(std::path::PathBuf, kode_bridge::IpcStreamClient),
|
(std::path::PathBuf, kode_bridge::IpcStreamClient),
|
||||||
Box<dyn std::error::Error + Send + Sync>,
|
Box<dyn std::error::Error + Send + Sync>,
|
||||||
@@ -253,26 +266,12 @@ impl LogsMonitor {
|
|||||||
let mut current = self.current.write().await;
|
let mut current = self.current.write().await;
|
||||||
current.logs.clear();
|
current.logs.clear();
|
||||||
current.mark_fresh();
|
current.mark_fresh();
|
||||||
|
logging!(
|
||||||
// Also reset monitoring level when clearing logs
|
info,
|
||||||
{
|
Type::Ipc,
|
||||||
let mut monitoring_level = self.current_monitoring_level.write().await;
|
true,
|
||||||
*monitoring_level = None;
|
"LogsMonitor: Cleared frontend logs (monitoring continues)"
|
||||||
}
|
);
|
||||||
|
|
||||||
// Abort current monitoring task
|
|
||||||
{
|
|
||||||
let mut handle = self.task_handle.write().await;
|
|
||||||
if let Some(task) = handle.take() {
|
|
||||||
task.abort();
|
|
||||||
logging!(
|
|
||||||
info,
|
|
||||||
Type::Ipc,
|
|
||||||
true,
|
|
||||||
"LogsMonitor: Stopped monitoring task due to clear_logs"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_logs_as_json(&self, level: Option<String>) -> serde_json::Value {
|
pub async fn get_logs_as_json(&self, level: Option<String>) -> serde_json::Value {
|
||||||
@@ -309,6 +308,10 @@ pub async fn start_logs_monitoring(level: Option<String>) {
|
|||||||
LogsMonitor::global().start_monitoring(level).await;
|
LogsMonitor::global().start_monitoring(level).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn stop_logs_monitoring() {
|
||||||
|
LogsMonitor::global().stop_monitoring().await;
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn clear_logs() {
|
pub async fn clear_logs() {
|
||||||
LogsMonitor::global().clear_logs().await;
|
LogsMonitor::global().clear_logs().await;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ pub mod monitor;
|
|||||||
pub mod traffic;
|
pub mod traffic;
|
||||||
|
|
||||||
pub use general::IpcManager;
|
pub use general::IpcManager;
|
||||||
pub use logs::{clear_logs, get_logs_json, start_logs_monitoring};
|
pub use logs::{clear_logs, get_logs_json, start_logs_monitoring, stop_logs_monitoring};
|
||||||
pub use memory::{get_current_memory, get_formatted_memory};
|
pub use memory::{get_current_memory, get_formatted_memory};
|
||||||
pub use traffic::{get_current_traffic, get_formatted_traffic};
|
pub use traffic::{get_current_traffic, get_formatted_traffic};
|
||||||
|
|
||||||
|
|||||||
@@ -355,6 +355,7 @@ mod app_init {
|
|||||||
// Logging and monitoring
|
// Logging and monitoring
|
||||||
cmd::get_clash_logs,
|
cmd::get_clash_logs,
|
||||||
cmd::start_logs_monitoring,
|
cmd::start_logs_monitoring,
|
||||||
|
cmd::stop_logs_monitoring,
|
||||||
cmd::clear_logs,
|
cmd::clear_logs,
|
||||||
cmd::get_traffic_data,
|
cmd::get_traffic_data,
|
||||||
cmd::get_memory_data,
|
cmd::get_memory_data,
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import { initGlobalLogService } from "@/services/global-log-service";
|
|||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { showNotice } from "@/services/noticeService";
|
import { showNotice } from "@/services/noticeService";
|
||||||
import { NoticeManager } from "@/components/base/NoticeManager";
|
import { NoticeManager } from "@/components/base/NoticeManager";
|
||||||
|
import { useLocalStorage } from "foxact/use-local-storage";
|
||||||
|
import { LogLevel } from "@/hooks/use-log-data";
|
||||||
|
|
||||||
const appWindow = getCurrentWebviewWindow();
|
const appWindow = getCurrentWebviewWindow();
|
||||||
export let portableFlag = false;
|
export let portableFlag = false;
|
||||||
@@ -154,6 +156,7 @@ const Layout = () => {
|
|||||||
const { verge } = useVerge();
|
const { verge } = useVerge();
|
||||||
const { clashInfo } = useClashInfo();
|
const { clashInfo } = useClashInfo();
|
||||||
const [enableLog] = useEnableLog();
|
const [enableLog] = useEnableLog();
|
||||||
|
const [logLevel] = useLocalStorage<LogLevel>("log:log-level", "info");
|
||||||
const { language, start_page } = verge ?? {};
|
const { language, start_page } = verge ?? {};
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
@@ -184,9 +187,9 @@ const Layout = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (clashInfo) {
|
if (clashInfo) {
|
||||||
const { server = "", secret = "" } = clashInfo;
|
const { server = "", secret = "" } = clashInfo;
|
||||||
initGlobalLogService(enableLog, "info");
|
initGlobalLogService(enableLog, logLevel);
|
||||||
}
|
}
|
||||||
}, [clashInfo, enableLog]);
|
}, [clashInfo, enableLog, logLevel]);
|
||||||
|
|
||||||
// 设置监听器
|
// 设置监听器
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ const LogPage = () => {
|
|||||||
changeLogLevel(newLevel);
|
changeLogLevel(newLevel);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleToggleLog = () => {
|
const handleToggleLog = async () => {
|
||||||
toggleLogEnabled();
|
await toggleLogEnabled();
|
||||||
setEnableLog(!enableLog);
|
setEnableLog(!enableLog);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -420,6 +420,10 @@ export async function startLogsMonitoring(level?: string) {
|
|||||||
return invoke<void>("start_logs_monitoring", { level });
|
return invoke<void>("start_logs_monitoring", { level });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function stopLogsMonitoring() {
|
||||||
|
return invoke<void>("stop_logs_monitoring");
|
||||||
|
}
|
||||||
|
|
||||||
export async function clearLogs() {
|
export async function clearLogs() {
|
||||||
return invoke<void>("clear_logs");
|
return invoke<void>("clear_logs");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { create } from "zustand";
|
|||||||
import {
|
import {
|
||||||
fetchLogsViaIPC,
|
fetchLogsViaIPC,
|
||||||
startLogsStreaming,
|
startLogsStreaming,
|
||||||
|
stopLogsStreaming,
|
||||||
clearLogs as clearLogsIPC,
|
clearLogs as clearLogsIPC,
|
||||||
} from "@/services/ipc-log-service";
|
} from "@/services/ipc-log-service";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
@@ -123,12 +124,21 @@ const clearIpcPolling = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 关闭全局日志连接 (仅IPC模式)
|
// 停止日志监控 (仅IPC模式)
|
||||||
export const closeGlobalLogConnection = () => {
|
export const stopGlobalLogMonitoring = async () => {
|
||||||
clearIpcPolling();
|
clearIpcPolling();
|
||||||
isInitializing = false; // 重置初始化标志
|
isInitializing = false; // 重置初始化标志
|
||||||
|
|
||||||
|
// 调用后端停止监控
|
||||||
|
await stopLogsStreaming();
|
||||||
|
|
||||||
useGlobalLogStore.setState({ isConnected: false });
|
useGlobalLogStore.setState({ isConnected: false });
|
||||||
console.log("[GlobalLog-IPC] 日志服务已关闭");
|
console.log("[GlobalLog-IPC] 日志监控已停止");
|
||||||
|
};
|
||||||
|
|
||||||
|
// 关闭全局日志连接 (仅IPC模式) - 保持向后兼容
|
||||||
|
export const closeGlobalLogConnection = async () => {
|
||||||
|
await stopGlobalLogMonitoring();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 切换日志级别 (仅IPC模式)
|
// 切换日志级别 (仅IPC模式)
|
||||||
@@ -150,7 +160,7 @@ export const changeLogLevel = (level: LogLevel) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 切换启用状态 (仅IPC模式)
|
// 切换启用状态 (仅IPC模式)
|
||||||
export const toggleLogEnabled = () => {
|
export const toggleLogEnabled = async () => {
|
||||||
const { enabled, currentLevel } = useGlobalLogStore.getState();
|
const { enabled, currentLevel } = useGlobalLogStore.getState();
|
||||||
const newEnabled = !enabled;
|
const newEnabled = !enabled;
|
||||||
|
|
||||||
@@ -160,14 +170,14 @@ export const toggleLogEnabled = () => {
|
|||||||
// IPC模式下直接启动
|
// IPC模式下直接启动
|
||||||
initGlobalLogService(newEnabled, currentLevel);
|
initGlobalLogService(newEnabled, currentLevel);
|
||||||
} else {
|
} else {
|
||||||
closeGlobalLogConnection();
|
await stopGlobalLogMonitoring();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 获取日志清理函数
|
// 获取日志清理函数 - 只清理前端日志,不停止监控
|
||||||
export const clearGlobalLogs = () => {
|
export const clearGlobalLogs = () => {
|
||||||
useGlobalLogStore.getState().clearLogs();
|
useGlobalLogStore.getState().clearLogs();
|
||||||
// 同时清理后端流式缓存
|
// 同时清理后端缓存的日志,但不停止监控
|
||||||
clearLogsIPC();
|
clearLogsIPC();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import {
|
import {
|
||||||
getClashLogs,
|
getClashLogs,
|
||||||
startLogsMonitoring,
|
startLogsMonitoring,
|
||||||
|
stopLogsMonitoring,
|
||||||
clearLogs as clearLogsCmd,
|
clearLogs as clearLogsCmd,
|
||||||
} from "@/services/cmds";
|
} from "@/services/cmds";
|
||||||
import dayjs from "dayjs";
|
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)
|
// Fetch logs using IPC command (now from streaming cache)
|
||||||
export const fetchLogsViaIPC = async (
|
export const fetchLogsViaIPC = async (
|
||||||
logLevel: LogLevel = "info",
|
logLevel: LogLevel = "info",
|
||||||
|
|||||||
Reference in New Issue
Block a user