"use client"; import { useState, useEffect } from "react"; import Card from "./Card"; export default function RequestLogger() { const [logs, setLogs] = useState([]); const [loading, setLoading] = useState(true); const [autoRefresh, setAutoRefresh] = useState(true); useEffect(() => { fetchLogs(); }, []); useEffect(() => { let interval; if (autoRefresh) { interval = setInterval(() => { fetchLogs(false); }, 3000); } return () => clearInterval(interval); }, [autoRefresh]); const fetchLogs = async (showLoading = true) => { if (showLoading) setLoading(true); try { const res = await fetch("/api/usage/request-logs"); if (res.ok) { const data = await res.json(); setLogs(data); } } catch (error) { console.error("Failed to fetch logs:", error); } finally { if (showLoading) setLoading(false); } }; return (

Request Logs

{loading && logs.length === 0 ? (
Loading logs...
) : logs.length === 0 ? (
No logs recorded yet.
) : ( {logs.map((log, i) => { const parts = log.split(" | "); if (parts.length < 7) return null; const status = parts[6]; const isPending = status.includes("PENDING"); const isFailed = status.includes("FAILED"); const isSuccess = status.includes("OK"); return ( ); })}
DateTime Model Provider Account In Out Status
{parts[0]} {parts[1]} {parts[2]} {parts[3]} {parts[4]} {parts[5]} {status}
)}
Logs are saved to log.txt in the application data directory.
); }