mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-29 01:25:33 +08:00
@@ -0,0 +1,119 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { settingsApi, type LogConfig } from "@/lib/api/settings";
|
||||
|
||||
const LOG_LEVELS = ["error", "warn", "info", "debug", "trace"] as const;
|
||||
|
||||
export function LogConfigPanel() {
|
||||
const { t } = useTranslation();
|
||||
const [config, setConfig] = useState<LogConfig>({
|
||||
enabled: true,
|
||||
level: "info",
|
||||
});
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
settingsApi
|
||||
.getLogConfig()
|
||||
.then(setConfig)
|
||||
.catch((e) => console.error("Failed to load log config:", e))
|
||||
.finally(() => setIsLoading(false));
|
||||
}, []);
|
||||
|
||||
const handleChange = async (updates: Partial<LogConfig>) => {
|
||||
const newConfig = { ...config, ...updates };
|
||||
setConfig(newConfig);
|
||||
try {
|
||||
await settingsApi.setLogConfig(newConfig);
|
||||
} catch (e) {
|
||||
console.error("Failed to save log config:", e);
|
||||
toast.error(String(e));
|
||||
setConfig(config);
|
||||
}
|
||||
};
|
||||
|
||||
if (isLoading) return null;
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-0.5">
|
||||
<Label>{t("settings.advanced.logConfig.enabled")}</Label>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t("settings.advanced.logConfig.enabledDescription")}
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
checked={config.enabled}
|
||||
onCheckedChange={(checked) => handleChange({ enabled: checked })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="space-y-0.5">
|
||||
<Label>{t("settings.advanced.logConfig.level")}</Label>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t("settings.advanced.logConfig.levelDescription")}
|
||||
</p>
|
||||
</div>
|
||||
<Select
|
||||
value={config.level}
|
||||
disabled={!config.enabled}
|
||||
onValueChange={(value) =>
|
||||
handleChange({ level: value as LogConfig["level"] })
|
||||
}
|
||||
>
|
||||
<SelectTrigger className="w-[120px]">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{LOG_LEVELS.map((level) => (
|
||||
<SelectItem key={level} value={level}>
|
||||
{t(`settings.advanced.logConfig.levels.${level}`)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{/* 日志级别说明 */}
|
||||
<div className="rounded-lg bg-muted/50 p-4 text-xs space-y-1.5">
|
||||
<p className="font-medium text-muted-foreground mb-2">
|
||||
{t("settings.advanced.logConfig.levelHint")}
|
||||
</p>
|
||||
<div className="grid gap-1 text-muted-foreground">
|
||||
<p>
|
||||
<span className="font-mono text-red-500">error</span> -{" "}
|
||||
{t("settings.advanced.logConfig.levelDesc.error")}
|
||||
</p>
|
||||
<p>
|
||||
<span className="font-mono text-orange-500">warn</span> -{" "}
|
||||
{t("settings.advanced.logConfig.levelDesc.warn")}
|
||||
</p>
|
||||
<p>
|
||||
<span className="font-mono text-blue-500">info</span> -{" "}
|
||||
{t("settings.advanced.logConfig.levelDesc.info")}
|
||||
</p>
|
||||
<p>
|
||||
<span className="font-mono text-green-500">debug</span> -{" "}
|
||||
{t("settings.advanced.logConfig.levelDesc.debug")}
|
||||
</p>
|
||||
<p>
|
||||
<span className="font-mono text-gray-500">trace</span> -{" "}
|
||||
{t("settings.advanced.logConfig.levelDesc.trace")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
ChevronDown,
|
||||
Zap,
|
||||
Globe,
|
||||
ScrollText,
|
||||
} from "lucide-react";
|
||||
import * as AccordionPrimitive from "@radix-ui/react-accordion";
|
||||
import { toast } from "sonner";
|
||||
@@ -44,6 +45,7 @@ import { AutoFailoverConfigPanel } from "@/components/proxy/AutoFailoverConfigPa
|
||||
import { FailoverQueueManager } from "@/components/proxy/FailoverQueueManager";
|
||||
import { UsageDashboard } from "@/components/usage/UsageDashboard";
|
||||
import { RectifierConfigPanel } from "@/components/settings/RectifierConfigPanel";
|
||||
import { LogConfigPanel } from "@/components/settings/LogConfigPanel";
|
||||
import { useSettings } from "@/hooks/useSettings";
|
||||
import { useImportExport } from "@/hooks/useImportExport";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -574,6 +576,28 @@ export function SettingsPage({
|
||||
<RectifierConfigPanel />
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
|
||||
<AccordionItem
|
||||
value="logConfig"
|
||||
className="rounded-xl glass-card overflow-hidden"
|
||||
>
|
||||
<AccordionTrigger className="px-6 py-4 hover:no-underline hover:bg-muted/50 data-[state=open]:bg-muted/50">
|
||||
<div className="flex items-center gap-3">
|
||||
<ScrollText className="h-5 w-5 text-cyan-500" />
|
||||
<div className="text-left">
|
||||
<h3 className="text-base font-semibold">
|
||||
{t("settings.advanced.logConfig.title")}
|
||||
</h3>
|
||||
<p className="text-sm text-muted-foreground font-normal">
|
||||
{t("settings.advanced.logConfig.description")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-6 pb-6 pt-4 border-t border-border/50">
|
||||
<LogConfigPanel />
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
<div className="pt-4">
|
||||
|
||||
@@ -208,6 +208,29 @@
|
||||
"responseGroup": "Response Rectification",
|
||||
"thinkingSignature": "Thinking Signature Rectification",
|
||||
"thinkingSignatureDescription": "Automatically fix Claude API errors caused by thinking signature validation failures"
|
||||
},
|
||||
"logConfig": {
|
||||
"title": "Log Management",
|
||||
"description": "Control log output level",
|
||||
"enabled": "Enable Logging",
|
||||
"enabledDescription": "Master switch, all logging will be disabled when turned off",
|
||||
"level": "Log Level",
|
||||
"levelDescription": "Set the minimum log level to output",
|
||||
"levels": {
|
||||
"error": "Error",
|
||||
"warn": "Warning",
|
||||
"info": "Info",
|
||||
"debug": "Debug",
|
||||
"trace": "Trace"
|
||||
},
|
||||
"levelHint": "Log level descriptions:",
|
||||
"levelDesc": {
|
||||
"error": "Critical errors only",
|
||||
"warn": "Errors + warnings",
|
||||
"info": "General operation info (default)",
|
||||
"debug": "Detailed info including SSE stream and request/response",
|
||||
"trace": "All logs, most verbose"
|
||||
}
|
||||
}
|
||||
},
|
||||
"language": "Language",
|
||||
|
||||
@@ -208,6 +208,29 @@
|
||||
"responseGroup": "レスポンス整流",
|
||||
"thinkingSignature": "Thinking 署名整流",
|
||||
"thinkingSignatureDescription": "Claude API の thinking 署名検証エラーを自動修正"
|
||||
},
|
||||
"logConfig": {
|
||||
"title": "ログ管理",
|
||||
"description": "ログ出力レベルを制御",
|
||||
"enabled": "ログを有効化",
|
||||
"enabledDescription": "マスタースイッチ、オフにするとすべてのログが無効になります",
|
||||
"level": "ログレベル",
|
||||
"levelDescription": "出力する最小ログレベルを設定",
|
||||
"levels": {
|
||||
"error": "エラー",
|
||||
"warn": "警告",
|
||||
"info": "情報",
|
||||
"debug": "デバッグ",
|
||||
"trace": "トレース"
|
||||
},
|
||||
"levelHint": "ログレベルの説明:",
|
||||
"levelDesc": {
|
||||
"error": "重大なエラーのみ",
|
||||
"warn": "エラー + 警告",
|
||||
"info": "一般的な操作情報(デフォルト)",
|
||||
"debug": "SSE ストリームとリクエスト/レスポンスを含む詳細情報",
|
||||
"trace": "すべてのログ、最も詳細"
|
||||
}
|
||||
}
|
||||
},
|
||||
"language": "言語",
|
||||
|
||||
@@ -208,6 +208,29 @@
|
||||
"responseGroup": "响应整流",
|
||||
"thinkingSignature": "Thinking 签名整流",
|
||||
"thinkingSignatureDescription": "自动修复 Claude API 中因 thinking 签名校验失败导致的请求错误"
|
||||
},
|
||||
"logConfig": {
|
||||
"title": "日志管理",
|
||||
"description": "控制日志输出级别",
|
||||
"enabled": "启用日志",
|
||||
"enabledDescription": "总开关,关闭后所有日志将被禁用",
|
||||
"level": "日志级别",
|
||||
"levelDescription": "设置输出的最低日志级别",
|
||||
"levels": {
|
||||
"error": "错误",
|
||||
"warn": "警告",
|
||||
"info": "信息",
|
||||
"debug": "调试",
|
||||
"trace": "跟踪"
|
||||
},
|
||||
"levelHint": "日志级别说明:",
|
||||
"levelDesc": {
|
||||
"error": "仅严重错误",
|
||||
"warn": "错误 + 警告信息",
|
||||
"info": "一般操作信息(默认)",
|
||||
"debug": "详细信息,包含 SSE 流和请求/响应详情",
|
||||
"trace": "全部日志,最详细"
|
||||
}
|
||||
}
|
||||
},
|
||||
"language": "界面语言",
|
||||
|
||||
@@ -142,9 +142,22 @@ export const settingsApi = {
|
||||
async setRectifierConfig(config: RectifierConfig): Promise<boolean> {
|
||||
return await invoke("set_rectifier_config", { config });
|
||||
},
|
||||
|
||||
async getLogConfig(): Promise<LogConfig> {
|
||||
return await invoke("get_log_config");
|
||||
},
|
||||
|
||||
async setLogConfig(config: LogConfig): Promise<boolean> {
|
||||
return await invoke("set_log_config", { config });
|
||||
},
|
||||
};
|
||||
|
||||
export interface RectifierConfig {
|
||||
enabled: boolean;
|
||||
requestThinkingSignature: boolean;
|
||||
}
|
||||
|
||||
export interface LogConfig {
|
||||
enabled: boolean;
|
||||
level: "error" | "warn" | "info" | "debug" | "trace";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user