import React, { useCallback, useEffect, useState, useMemo } from 'react'; import { useSettings } from '~/lib/hooks/useSettings'; import { toast } from 'react-toastify'; import { Switch } from '~/components/ui/Switch'; import { logStore, type LogEntry } from '~/lib/stores/logs'; export default function EventLogsTab() { const {} = useSettings(); const [logLevel, setLogLevel] = useState('info'); const [autoScroll, setAutoScroll] = useState(true); const [searchQuery, setSearchQuery] = useState(''); const [, forceUpdate] = useState({}); useEffect(() => { // Add some initial logs for testing logStore.logSystem('System started', { version: '1.0.0' }); logStore.logWarning('High memory usage detected', { memoryUsage: '85%' }); logStore.logError('Failed to connect to provider', new Error('Connection timeout'), { provider: 'OpenAI' }); }, []); const handleClearLogs = useCallback(() => { if (confirm('Are you sure you want to clear all logs?')) { logStore.clearLogs(); toast.success('Logs cleared successfully'); forceUpdate({}); // Force a re-render after clearing logs } }, []); const handleExportLogs = useCallback(() => { try { const logText = logStore .getLogs() .map( (log) => `[${log.level.toUpperCase()}] ${log.timestamp} - ${log.message}${ log.details ? '\nDetails: ' + JSON.stringify(log.details, null, 2) : '' }`, ) .join('\n\n'); const blob = new Blob([logText], { type: 'text/plain' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `event-logs-${new Date().toISOString()}.txt`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); toast.success('Logs exported successfully'); } catch (error) { toast.error('Failed to export logs'); console.error('Export error:', error); } }, []); const filteredLogs = useMemo(() => { return logStore.getFilteredLogs(logLevel, undefined, searchQuery); }, [logLevel, searchQuery]); const getLevelColor = (level: LogEntry['level']) => { switch (level) { case 'info': return 'text-blue-500'; case 'warning': return 'text-yellow-500'; case 'error': return 'text-red-500'; case 'debug': return 'text-gray-500'; default: return 'text-bolt-elements-textPrimary'; } }; return (

Event Logs

Auto-scroll
setSearchQuery(e.target.value)} className="bg-bolt-elements-bg-depth-2 text-bolt-elements-textPrimary rounded-lg px-3 py-1.5 text-sm flex-1" />
{filteredLogs.length === 0 ? (
No logs found
) : ( filteredLogs.map((log, index) => (
[{log.level.toUpperCase()}] {new Date(log.timestamp).toLocaleString()} {log.message}
{log.details && (
                  {JSON.stringify(log.details, null, 2)}
                
)}
)) )}
); }