import React from 'react'; import { CaddyAccessLog } from '../api/logs'; import { format } from 'date-fns'; interface LogTableProps { logs: CaddyAccessLog[]; isLoading: boolean; } export const LogTable: React.FC = ({ logs, isLoading }) => { if (isLoading) { return (
Loading logs...
); } if (!logs || logs.length === 0) { return (
No logs found matching criteria.
); } return (
{logs.map((log, idx) => { // Check if this is a structured access log or a plain text system log const isAccessLog = log.status > 0 || (log.request && log.request.method); if (!isAccessLog) { return ( ); } return ( )})}
Time Status Method Host Path IP Latency Message
{format(new Date(log.ts * 1000), 'MMM d HH:mm:ss')} {log.msg}
{format(new Date(log.ts * 1000), 'MMM d HH:mm:ss')} {log.status > 0 && ( = 500 ? 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200' : log.status >= 400 ? 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200' : log.status >= 300 ? 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200' : 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200'}`} data-testid={`status-${log.status}`} > {log.status} )} {log.request?.method} {log.request?.host} {log.request?.uri} {log.request?.remote_ip} {log.duration > 0 ? (log.duration * 1000).toFixed(2) + 'ms' : ''} {log.msg}
); };