()
| 109 | }; |
| 110 | |
| 111 | export const useLogStream = () => { |
| 112 | const [logs, setLogs] = useState<LogEntry[]>([]); |
| 113 | |
| 114 | useEffect(() => { |
| 115 | const flushInterval = setInterval(() => { |
| 116 | setLogs(logBuffer.toArray()); |
| 117 | }, FLUSH_INTERVAL_MS); |
| 118 | |
| 119 | return () => { |
| 120 | clearInterval(flushInterval); |
| 121 | }; |
| 122 | }, []); |
| 123 | |
| 124 | const clearLogs = useCallback(() => { |
| 125 | logBuffer.clear(); |
| 126 | }, []); |
| 127 | |
| 128 | const scopes = useMemo( |
| 129 | () => [...new Set(logs.map((l) => l.source.scope).filter(Boolean))], |
| 130 | [logs], |
| 131 | ); |
| 132 | |
| 133 | const targets = useMemo( |
| 134 | () => [...new Set(logs.map((l) => l.target).filter(Boolean))], |
| 135 | [logs], |
| 136 | ); |
| 137 | |
| 138 | return { |
| 139 | logs, |
| 140 | scopes, |
| 141 | targets, |
| 142 | clearLogs, |
| 143 | }; |
| 144 | }; |
no test coverage detected