Chroma logs in Frontend (#12131)

* Chroma logs in frontend

* fix lint
This commit is contained in:
Jason Hunter 2024-06-24 08:19:50 -04:00 committed by Nicolas Mowen
parent d93d6262ce
commit dd7fd16b69
2 changed files with 47 additions and 6 deletions

View File

@ -12,5 +12,5 @@ export type LogLine = {
content: string;
};
export const logTypes = ["frigate", "go2rtc", "nginx"] as const;
export const logTypes = ["frigate", "go2rtc", "nginx", "chroma"] as const;
export type LogType = (typeof logTypes)[number];

View File

@ -1,13 +1,14 @@
import { LogLine, LogSeverity, LogType } from "@/types/log";
const pythonSeverity = /(DEBUG)|(INFO)|(WARNING)|(ERROR)/;
const frigateDateStamp = /\[[\d\s-:]*]/;
const frigateSeverity = /(DEBUG)|(INFO)|(WARNING)|(ERROR)/;
const frigateSection = /[\w.]*/;
const goSeverity = /(DEB )|(INF )|(WRN )|(ERR )/;
const goSection = /\[[\w]*]/;
const ngSeverity = /(GET)|(POST)|(PUT)|(PATCH)|(DELETE)/;
const httpMethods = /(GET)|(POST)|(PUT)|(PATCH)|(DELETE)/;
export function parseLogLines(logService: LogType, logs: string[]) {
if (logService == "frigate") {
@ -45,7 +46,7 @@ export function parseLogLines(logService: LogType, logs: string[]) {
return {
dateStamp: match.toString().slice(1, -1),
severity: frigateSeverity
severity: pythonSeverity
.exec(line)
?.at(0)
?.toString()
@ -69,7 +70,7 @@ export function parseLogLines(logService: LogType, logs: string[]) {
let section =
goSection.exec(line)?.toString()?.slice(1, -1) ?? "startup";
if (frigateSeverity.exec(section)) {
if (pythonSeverity.exec(section)) {
section = "startup";
}
@ -122,11 +123,51 @@ export function parseLogLines(logService: LogType, logs: string[]) {
return {
dateStamp: line.substring(0, 19),
severity: "info",
section: ngSeverity.exec(line)?.at(0)?.toString() ?? "META",
section: httpMethods.exec(line)?.at(0)?.toString() ?? "META",
content: line.substring(line.indexOf(" ", 20)).trim(),
};
})
.filter((value) => value != null) as LogLine[];
} else if (logService == "chroma") {
return logs
.map((line) => {
const match = frigateDateStamp.exec(line);
if (!match) {
const infoIndex = line.indexOf("[INFO]");
if (infoIndex != -1) {
return {
dateStamp: line.substring(0, 19),
severity: "info",
section: "startup",
content: line.substring(infoIndex + 6).trim(),
};
}
return null;
}
const startup =
line.indexOf("Starting component") !== -1 ||
line.indexOf("startup") !== -1 ||
line.indexOf("Started") !== -1 ||
line.indexOf("Uvicorn") !== -1;
const api = !!httpMethods.exec(line);
const tag = startup ? "startup" : api ? "API" : "server";
return {
dateStamp: match.toString().slice(1, -1),
severity: pythonSeverity
.exec(line)
?.at(0)
?.toString()
?.toLowerCase() as LogSeverity,
section: tag,
content: line.substring(match.index + match[0].length).trim(),
};
})
.filter((value) => value != null) as LogLine[];
}
return [];