Ignore the Metal selector when a QEMU message reports a successful precision note. Reuse the same severity for log rows and the unread-error badge.
35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import { LogEntry } from '../types'
|
|
|
|
type LogLevel = 'info' | 'warn' | 'error'
|
|
|
|
export interface LogLine extends LogEntry {
|
|
id: number
|
|
level: LogLevel
|
|
}
|
|
|
|
const MAX_LOG_LINES = 2000
|
|
|
|
// Progress no longer reaches the log: the backend turns it into tasks
|
|
// (tasks.go, "reims:task"). Levels are still guessed from the text until the
|
|
// backend tags them explicitly.
|
|
const ERROR_RE = /\b(error|failed|fatal|panic)\b/i
|
|
const WARN_RE = /\bwarn(ing)?\b/i
|
|
// Successful vGPU precision notes include the Metal selector's error: argument.
|
|
const PRECISION_NOTE_PREFIX = /^(?:\[QEMU\] )?reims-vgpu: [\w:]+: metal2vulkan-runtime made it with a precision note \(metal2vulkan-degrade-[a-z0-9-]+\): /
|
|
|
|
let nextId = 1
|
|
|
|
export function createLogLine(entry: LogEntry): LogLine {
|
|
const ts = typeof entry?.ts === 'string' ? entry.ts : ''
|
|
const source = typeof entry?.source === 'string' ? entry.source : ''
|
|
const line = typeof entry?.line === 'string' ? entry.line : String(entry?.line ?? '')
|
|
const message = line.replace(PRECISION_NOTE_PREFIX, '')
|
|
const level: LogLevel = ERROR_RE.test(message) ? 'error' : WARN_RE.test(message) ? 'warn' : 'info'
|
|
return { ts, source, line, id: nextId++, level }
|
|
}
|
|
|
|
export function appendLog(prev: LogLine[], line: LogLine): LogLine[] {
|
|
const next = [...prev, line]
|
|
return next.length > MAX_LOG_LINES ? next.slice(next.length - MAX_LOG_LINES) : next
|
|
}
|