Properly parse go2rtc severity

This commit is contained in:
Nicolas Mowen 2024-04-05 09:36:04 -06:00
parent 0c7752ca36
commit 9f5d555670

View File

@ -15,7 +15,7 @@ const frigateDateStamp = /\[[\d\s-:]*]/;
const frigateSeverity = /(DEBUG)|(INFO)|(WARNING)|(ERROR)/; const frigateSeverity = /(DEBUG)|(INFO)|(WARNING)|(ERROR)/;
const frigateSection = /[\w.]*/; const frigateSection = /[\w.]*/;
const goSeverity = /(DEB )|(INF )|(WARN )|(ERR )/; const goSeverity = /(DEB )|(INF )|(WRN )|(ERR )/;
const goSection = /\[[\w]*]/; const goSection = /\[[\w]*]/;
const ngSeverity = /(GET)|(POST)|(PUT)|(PATCH)|(DELETE)/; const ngSeverity = /(GET)|(POST)|(PUT)|(PATCH)|(DELETE)/;
@ -152,9 +152,28 @@ function Logs() {
contentStart = line.indexOf(section) + section.length + 2; contentStart = line.indexOf(section) + section.length + 2;
} }
let severityCat: LogSeverity;
switch (severity?.at(0)?.toString().trim()) {
case "INF":
severityCat = "info";
break;
case "WRN":
severityCat = "warning";
break;
case "ERR":
severityCat = "error";
break;
case "DBG":
case "TRC":
severityCat = "debug";
break;
default:
severityCat = "info";
}
return { return {
dateStamp: line.substring(0, 19), dateStamp: line.substring(0, 19),
severity: "INFO", severity: severityCat,
section: section, section: section,
content: line.substring(contentStart).trim(), content: line.substring(contentStart).trim(),
}; };
@ -169,7 +188,7 @@ function Logs() {
return { return {
dateStamp: line.substring(0, 19), dateStamp: line.substring(0, 19),
severity: "INFO", severity: "info",
section: ngSeverity.exec(line)?.at(0)?.toString() ?? "META", section: ngSeverity.exec(line)?.at(0)?.toString() ?? "META",
content: line.substring(line.indexOf(" ", 20)).trim(), content: line.substring(line.indexOf(" ", 20)).trim(),
}; };
@ -299,7 +318,7 @@ function Logs() {
value={item} value={item}
aria-label={`Select ${item}`} aria-label={`Select ${item}`}
> >
<div className="capitalize">{`${item} Logs`}</div> <div className="capitalize">{item}</div>
</ToggleGroupItem> </ToggleGroupItem>
))} ))}
</ToggleGroup> </ToggleGroup>
@ -334,7 +353,7 @@ function Logs() {
ref={contentRef} ref={contentRef}
className="w-full h-min my-2 font-mono text-sm sm:py-2 whitespace-pre-wrap overflow-auto no-scrollbar bg-primary border border-secondary rounded-md" className="w-full h-min my-2 font-mono text-sm sm:py-2 whitespace-pre-wrap overflow-auto no-scrollbar bg-primary border border-secondary rounded-md"
> >
<div className="grid grid-cols-5 sm:grid-cols-8 md:grid-cols-12 *:p-2 *:text-sm *:text-secondary-foreground"> <div className="grid grid-cols-5 sm:grid-cols-8 md:grid-cols-12 *:p-2 *:text-sm *:text-primary-foreground/40">
<div className="p-1 flex items-center capitalize">Type</div> <div className="p-1 flex items-center capitalize">Type</div>
<div className="col-span-2 sm:col-span-1 flex items-center"> <div className="col-span-2 sm:col-span-1 flex items-center">
Timestamp Timestamp
@ -387,11 +406,11 @@ function LogLineData({ startRef, className, line }: LogLineDataProps) {
const severityClassName = useMemo(() => { const severityClassName = useMemo(() => {
switch (line.severity) { switch (line.severity) {
case "info": case "info":
return "text-primary-foreground/40 bg-muted"; return "text-primary-foreground/60 bg-secondary hover:bg-secondary/60";
case "warning": case "warning":
return "text-warning-foreground bg-warning"; return "text-warning-foreground bg-warning hover:bg-warning/80";
case "error": case "error":
return "text-destructive-foreground bg-destructive"; return "text-destructive-foreground bg-destructive hover:bg-destructive/80";
} }
}, [line]); }, [line]);
@ -402,7 +421,7 @@ function LogLineData({ startRef, className, line }: LogLineDataProps) {
> >
<div className="h-full p-1 flex items-center gap-2"> <div className="h-full p-1 flex items-center gap-2">
<div <div
className={`py-[1px] px-1 capitalize text-xs rounded-md ${severityClassName}`} className={`py-[1px] px-1 capitalize text-xs rounded-md cursor-pointer ${severityClassName}`}
> >
{line.severity} {line.severity}
</div> </div>