import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; import { Textarea } from "@/components/ui/textarea"; import { getErrorMessage, useGetCoreConfigQuery, useUpdateCoreConfigMutation } from "@/lib/store"; import { CoreConfig, DefaultCoreConfig } from "@/lib/types/config"; import { parseArrayFromText } from "@/lib/utils/array"; import { RbacOperation, RbacResource, useRbac } from "@enterprise/lib"; import { useCallback, useEffect, useMemo, useState } from "react"; import { toast } from "sonner"; export default function LoggingView() { const hasSettingsUpdateAccess = useRbac(RbacResource.Settings, RbacOperation.Update); const { data: bifrostConfig } = useGetCoreConfigQuery({ fromDB: true }); const config = bifrostConfig?.client_config; const [updateCoreConfig, { isLoading }] = useUpdateCoreConfigMutation(); const [localConfig, setLocalConfig] = useState(DefaultCoreConfig); const [needsRestart, setNeedsRestart] = useState(false); const [loggingHeadersText, setLoggingHeadersText] = useState(""); useEffect(() => { if (config) { setLocalConfig(config); setLoggingHeadersText(config.logging_headers?.join(", ") || ""); } }, [config]); const hasChanges = useMemo(() => { if (!config) return false; return ( localConfig.enable_logging !== config.enable_logging || localConfig.disable_content_logging !== config.disable_content_logging || localConfig.log_retention_days !== config.log_retention_days || localConfig.hide_deleted_virtual_keys_in_filters !== config.hide_deleted_virtual_keys_in_filters || JSON.stringify(localConfig.logging_headers || []) !== JSON.stringify(config.logging_headers || []) ); }, [config, localConfig]); const handleConfigChange = useCallback((field: keyof CoreConfig, value: boolean | number | string[]) => { setLocalConfig((prev) => ({ ...prev, [field]: value })); if (field === "enable_logging" || field === "disable_content_logging") { setNeedsRestart(true); } }, []); const handleLoggingHeadersChange = useCallback((value: string) => { setLoggingHeadersText(value); setLocalConfig((prev) => ({ ...prev, logging_headers: parseArrayFromText(value) })); }, []); const handleSave = useCallback(async () => { if (!bifrostConfig) { toast.error("Configuration not loaded"); return; } // Validate log retention days if (localConfig.log_retention_days < 1) { toast.error("Log retention days must be at least 1 day"); return; } try { await updateCoreConfig({ ...bifrostConfig, client_config: localConfig }).unwrap(); toast.success("Logging configuration updated successfully."); } catch (error) { toast.error(getErrorMessage(error)); } }, [bifrostConfig, localConfig, updateCoreConfig]); return (

Logs Settings

Configure logging settings for requests and responses.

{/* Enable Logs */}

Enable logging of requests and responses to a SQL database. This can add 40-60mb of overhead to the system memory. {!bifrostConfig?.is_logs_connected && ( Requires logs store to be configured and enabled in config.json. )}

{ if (bifrostConfig?.is_logs_connected) { handleConfigChange("enable_logging", checked); } }} />
{needsRestart && }
{/* Disable Content Logging - Only show when logging is enabled */} {localConfig.enable_logging && bifrostConfig?.is_logs_connected && (

When enabled, only usage metadata (latency, cost, token count, etc.) will be logged. Request/response content will not be stored.

handleConfigChange("disable_content_logging", checked)} />
{needsRestart && }
)} {/* Log Retention Days */} {localConfig.enable_logging && bifrostConfig?.is_logs_connected && (

Number of days to retain logs in the database. Minimum is 1 day. Older logs will be automatically deleted.

{ const value = parseInt(e.target.value) || 1; handleConfigChange("log_retention_days", Math.max(1, value)); }} className="w-24" />
)}

When enabled, deleted virtual keys are excluded from Virtual Keys filter options in Logs, Dashboard, and MCP Logs.

handleConfigChange("hide_deleted_virtual_keys_in_filters", checked)} />
{/* Logging Headers */} {localConfig.enable_logging && bifrostConfig?.is_logs_connected && (

Comma-separated list of request headers to capture in log metadata. Values are extracted from incoming requests and stored in the metadata field of log entries. Headers with the x-bf-lh- prefix are always captured automatically.