"use client"; import { Card, CardContent, CardHeader, CardTitle } from "@kandev/ui/card"; import { Button } from "@kandev/ui/button"; import { Spinner } from "@kandev/ui/spinner"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@kandev/ui/table"; import { Badge } from "@kandev/ui/badge"; import { IconCopy, IconDownload, IconFileText, IconRefresh } from "@tabler/icons-react"; import { useLogFiles } from "@/hooks/domains/system/use-log-files"; import { useLogTail } from "@/hooks/domains/system/use-log-tail"; import { buildLogDownloadUrl } from "@/lib/api/domains/system-api"; import { formatBytes } from "@/lib/utils/format-bytes"; import { useActionFeedback, type ActionFeedbackState } from "@/hooks/use-action-feedback"; import { ActionButtonContent } from "./action-button-content"; function formatTimestamp(iso: string): string { if (!iso) return "-"; const d = new Date(iso); if (Number.isNaN(d.getTime())) return iso; return d.toLocaleString(); } function TailContent({ tail, loading, inMemoryOnly, }: { tail: string[]; loading: boolean; inMemoryOnly: boolean; }) { if (loading && tail.length === 0) { return (
Loading log...
); } if (tail.length === 0) { return (

No recent log activity captured yet. Logs will appear as Kandev does work.

); } return (
{inMemoryOnly && (

Showing the in-memory log buffer (last ~2000 entries). Kandev is currently logging to the terminal, not to a file - file rotation is disabled. Set logging.outputPath{" "} in config.yaml to a file path to enable downloadable log files.

)}
        {tail.join("\n")}
      
); } function buildTailFilename(): string { // YYYY-MM-DDTHH-MM-SS to mirror lumberjack's rotation naming, minus the // colons (which are invalid on Windows). The user can rename freely. const stamp = new Date().toISOString().replace(/:/g, "-").replace(/\..+$/, ""); return `kandev-tail-${stamp}.log`; } function downloadTailAsFile(tail: string[]) { if (typeof window === "undefined" || tail.length === 0) return; const blob = new Blob([tail.join("\n") + "\n"], { type: "text/plain" }); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = buildTailFilename(); document.body.appendChild(a); a.click(); a.remove(); URL.revokeObjectURL(url); } function TailHeader({ tail, current, refreshState, copyState, onRefresh, onCopy, }: { tail: string[]; current: ReturnType["files"][number] | undefined; refreshState: ActionFeedbackState; copyState: ActionFeedbackState; onRefresh: () => void; onCopy: () => void; }) { const hasTail = tail.length > 0; return (
{current ? ( ) : ( )}
); } export function LogViewer() { const { files, isLoading: filesLoading } = useLogFiles(); const { tail, isLoading: tailLoading, reload: reloadTail } = useLogTail(1000); const refreshFeedback = useActionFeedback(); const copyFeedback = useActionFeedback(); const onRefresh = () => void refreshFeedback.run(async () => { await reloadTail(); }); const onCopy = () => void copyFeedback.run(async () => { if (typeof navigator === "undefined" || !navigator.clipboard) { throw new Error("Clipboard API not available"); } await navigator.clipboard.writeText(tail.join("\n") + "\n"); }); const current = files.find((f) => f.current); const inMemoryOnly = !filesLoading && files.length === 0; return (
Recent log output Log files {!files.length && filesLoading && (
Loading files...
)} {files.length > 0 && ( Name Kind Size Modified Actions {files.map((f) => ( {f.name} {f.current ? "current" : "rotated"} {formatBytes(f.size)} {formatTimestamp(f.mtime)} ))}
)} {!filesLoading && files.length === 0 && (

No log files found. Kandev may be logging to stdout (no file rotation configured).

)}
); }