import { useEffect, useRef, useState } from 'react' type LogRecord = { ts?: string level?: string logger?: string msg?: string } export function Logs() { const [lines, setLines] = useState([]) const bottomRef = useRef(null) useEffect(() => { const proto = window.location.protocol === 'https:' ? 'wss:' : 'ws:' const ws = new WebSocket(`${proto}//${window.location.host}/ws/logs`) ws.onmessage = (ev) => { try { const rec = JSON.parse(ev.data as string) as LogRecord setLines((prev) => { const next = [...prev, rec] return next.length > 500 ? next.slice(-500) : next }) } catch { /* ignore */ } } return () => ws.close() }, []) useEffect(() => { bottomRef.current?.scrollIntoView({ behavior: 'smooth' }) }, [lines.length]) return (

Logy EMS

Stream z backendu (WebSocket)

          {lines.map((r, i) => (
            
{r.ts ?? '—'} [{r.level ?? '?'}] {r.logger ?? ''}: {r.msg ?? ''}
))}
) }