Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

feat(settings): add toggle to hide health check logs with caching

nyatoru4b137d8e7232
diff --git a/src/app/(dashboard)/dashboard/settings/components/AppearanceTab.tsx b/src/app/(dashboard)/dashboard/settings/components/AppearanceTab.tsx
index c367c499ad..957377437f 100644
--- a/src/app/(dashboard)/dashboard/settings/components/AppearanceTab.tsx
+++ b/src/app/(dashboard)/dashboard/settings/components/AppearanceTab.tsx
@@ -1,11 +1,39 @@
"use client";
+import { useState, useEffect } from "react";
import { Card, Toggle } from "@/shared/components";
import { useTheme } from "@/shared/hooks/useTheme";
import { cn } from "@/shared/utils/cn";
export default function AppearanceTab() {
const { theme, setTheme, isDark } = useTheme();
+ const [settings, setSettings] = useState<any>({});
+ const [loading, setLoading] = useState(true);
+
+ useEffect(() => {
+ fetch("/api/settings")
+ .then((res) => res.json())
+ .then((data) => {
+ setSettings(data);
+ setLoading(false);
+ })
+ .catch(() => setLoading(false));
+ }, []);
+
+ const updateSetting = async (key: string, value: any) => {
+ try {
+ const res = await fetch("/api/settings", {
+ method: "PATCH",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ [key]: value }),
+ });
+ if (res.ok) {
+ setSettings((prev) => ({ ...prev, [key]: value }));
+ }
+ } catch (err) {
+ console.error(`Failed to update ${key}:`, err);
+ }
+ };
return (
<Card>
@@ -53,6 +81,22 @@ export default function AppearanceTab() {
))}
</div>
</div>
+
+ <div className="pt-4 border-t border-border">
+ <div className="flex items-center justify-between">
+ <div>
+ <p className="font-medium">Hide Health Check Logs</p>
+ <p className="text-sm text-text-muted">
+ When ON, suppress [HealthCheck] messages in server console
+ </p>
+ </div>
+ <Toggle
+ checked={settings.hideHealthCheckLogs === true}
+ onChange={() => updateSetting("hideHealthCheckLogs", !settings.hideHealthCheckLogs)}
+ disabled={loading}
+ />
+ </div>
+ </div>
</div>
</Card>
);
diff --git a/src/app/api/settings/route.ts b/src/app/api/settings/route.ts
index 9e427f1639..b4aa561c61 100644
--- a/src/app/api/settings/route.ts
+++ b/src/app/api/settings/route.ts
@@ -1,5 +1,6 @@
import { NextResponse } from "next/server";
import { getSettings, updateSettings } from "@/lib/localDb";
+import { clearHealthCheckLogCache } from "@/lib/tokenHealthCheck";
import bcrypt from "bcryptjs";
import { updateSettingsSchema, validateBody } from "@/shared/validation/schemas";
@@ -61,6 +62,12 @@ export async function PATCH(request) {
}
const settings = await updateSettings(body);
+
+ // Clear health check log cache if that setting was updated
+ if ("hideHealthCheckLogs" in body) {
+ clearHealthCheckLogCache();
+ }
+
const { password, ...safeSettings } = settings;
return NextResponse.json(safeSettings);
} catch (error) {
diff --git a/src/lib/tokenHealthCheck.ts b/src/lib/tokenHealthCheck.ts
index 9ac1a50a80..0a2ac7dfa4 100644
--- a/src/lib/tokenHealthCheck.ts
+++ b/src/lib/tokenHealthCheck.ts
@@ -10,7 +10,7 @@
* updates the DB, and logs the result.
*/
-import { getProviderConnections, updateProviderConnection } from "@/lib/localDb";
+import { getProviderConnections, updateProviderConnection, getSettings } from "@/lib/localDb";
import {
getAccessToken,
supportsTokenRefresh,
@@ -22,6 +22,52 @@ const TICK_MS = 60 * 1000; // sweep interval: every 60 seconds
const DEFAULT_HEALTH_CHECK_INTERVAL_MIN = 60; // default per-connection interval
const LOG_PREFIX = "[HealthCheck]";
+// ── Logging helper ───────────────────────────────────────────────────────────
+let cachedHideLogs: boolean | null = null;
+let cacheTimestamp = 0;
+const CACHE_TTL = 30_000; // Cache settings for 30 seconds
+
+async function shouldHideLogs(): Promise<boolean> {
+ const now = Date.now();
+ if (cachedHideLogs !== null && now - cacheTimestamp < CACHE_TTL) {
+ return cachedHideLogs;
+ }
+ try {
+ const settings = await getSettings();
+ cachedHideLogs = settings.hideHealthCheckLogs === true;
+ cacheTimestamp = now;
+ return cachedHideLogs;
+ } catch {
+ return false;
+ }
+}
+
+function log(message: string, ...args: any[]) {
+ shouldHideLogs().then((hide) => {
+ if (!hide) console.log(message, ...args);
+ });
+}
+
+function logWarn(message: string, ...args: any[]) {
+ shouldHideLogs().then((hide) => {
+ if (!hide) console.warn(message, ...args);
+ });
+}
+
+function logError(message: string, ...args: any[]) {
+ shouldHideLogs().then((hide) => {
+ if (!hide) console.error(message, ...args);
+ });
+}
+
+/**
+ * Clear the cached hideLogs setting (call when settings are updated).
+ */
+export function clearHealthCheckLogCache() {
+ cachedHideLogs = null;
+ cacheTimestamp = 0;
+}
+
// ── Singleton guard ──────────────────────────────────────────────────────────
let initialized = false;
let intervalHandle = null;
@@ -33,9 +79,7 @@ export function initTokenHealthCheck() {
if (initialized) return;
initialized = true;
- console.log(
- `${LOG_PREFIX} Starting proactive token health-check (tick every ${TICK_MS / 1000}s)`
- );
+ log(`${LOG_PREFIX} Starting proactive token health-check (tick every ${TICK_MS / 1000}s)`);
// Run first sweep after a short delay so the server finishes booting
setTimeout(() => {
@@ -67,11 +111,11 @@ async function sweep() {
await checkConnection(conn);
} catch (err) {
// Per-connection isolation: one failure never blocks others
- console.error(`${LOG_PREFIX} Error checking ${conn.name || conn.id}:`, err.message);
+ logError(`${LOG_PREFIX} Error checking ${conn.name || conn.id}:`, err.message);
}
}
} catch (err) {
- console.error(`${LOG_PREFIX} Sweep error:`, err.message);
+ logError(`${LOG_PREFIX} Sweep error:`, err.message);
}
}
@@ -91,7 +135,7 @@ async function checkConnection(conn) {
if (!supportsTokenRefresh(conn.provider)) {
const now = new Date().toISOString();
await updateProviderConnection(conn.id, { lastHealthCheckAt: now });
- console.log(
+ log(
`${LOG_PREFIX} Skipping ${conn.provider}/${conn.name || conn.email || conn.id} (refresh unsupported)`
);
return;
@@ -103,7 +147,7 @@ async function checkConnection(conn) {
// Not yet due
if (Date.now() - lastCheck < intervalMs) return;
- console.log(
+ log(
`${LOG_PREFIX} Refreshing ${conn.provider}/${conn.name || conn.email || conn.id} (interval: ${intervalMin}min)`
);
@@ -114,10 +158,17 @@ async function checkConnection(conn) {
providerSpecificData: conn.providerSpecificData,
};
+ const hideLogs = await shouldHideLogs();
const result = await getAccessToken(conn.provider, credentials, {
- info: (tag, msg) => console.log(`${LOG_PREFIX} [${tag}] ${msg}`),
- warn: (tag, msg) => console.warn(`${LOG_PREFIX} [${tag}] ${msg}`),
- error: (tag, msg, extra) => console.error(`${LOG_PREFIX} [${tag}] ${msg}`, extra || ""),
+ info: (tag, msg) => {
+ if (!hideLogs) console.log(`${LOG_PREFIX} [${tag}] ${msg}`);
+ },
+ warn: (tag, msg) => {
+ if (!hideLogs) console.warn(`${LOG_PREFIX} [${tag}] ${msg}`);
+ },
+ error: (tag, msg, extra) => {
+ if (!hideLogs) console.error(`${LOG_PREFIX} [${tag}] ${msg}`, extra || "");
+ },
});
const now = new Date().toISOString();
@@ -138,7 +189,7 @@ async function checkConnection(conn) {
isActive: false,
refreshToken: null,
});
- console.error(
+ logError(
`${LOG_PREFIX} ✗ ${conn.provider}/${conn.name || conn.email || conn.id} — ` +
`Refresh token is permanently invalid (${result.error}). ` +
`Connection deactivated. Re-authenticate to restore.`
@@ -168,7 +219,7 @@ async function checkConnection(conn) {
}
await updateProviderConnection(conn.id, updateData);
- console.log(`${LOG_PREFIX} ✓ ${conn.provider}/${conn.name || conn.email || conn.id} refreshed`);
+ log(`${LOG_PREFIX} ✓ ${conn.provider}/${conn.name || conn.email || conn.id} refreshed`);
} else {
// Refresh failed — record but don't disable the connection
await updateProviderConnection(conn.id, {
@@ -180,7 +231,7 @@ async function checkConnection(conn) {
lastErrorSource: "oauth",
errorCode: "refresh_failed",
});
- console.warn(
+ logWarn(
`${LOG_PREFIX} ✗ ${conn.provider}/${conn.name || conn.email || conn.id} refresh failed`
);
}
diff --git a/src/shared/validation/schemas.ts b/src/shared/validation/schemas.ts
index 5cc3abe50c..5f5fdcd730 100644
--- a/src/shared/validation/schemas.ts
+++ b/src/shared/validation/schemas.ts
@@ -72,6 +72,7 @@ export const updateSettingsSchema = z.object({
setupComplete: z.boolean().optional(),
requireAuthForModels: z.boolean().optional(),
blockedProviders: z.array(z.string().max(100)).optional(),
+ hideHealthCheckLogs: z.boolean().optional(),
});
// ──── Auth Schemas ────