diff --git a/web/src/types/log.ts b/web/src/types/log.ts index 407f67e6d..235a6ea93 100644 --- a/web/src/types/log.ts +++ b/web/src/types/log.ts @@ -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]; diff --git a/web/src/utils/logUtil.ts b/web/src/utils/logUtil.ts index a481e145e..5c787c396 100644 --- a/web/src/utils/logUtil.ts +++ b/web/src/utils/logUtil.ts @@ -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 [];