Skip to content

Commit

Permalink
Chroma logs in Frontend (#12131)
Browse files Browse the repository at this point in the history
* Chroma logs in frontend

* fix lint
  • Loading branch information
hunterjm authored and NickM-27 committed Jul 9, 2024
1 parent b13bdd0 commit 784f4f8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion web/src/types/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
51 changes: 46 additions & 5 deletions web/src/utils/logUtil.ts
Original file line number Diff line number Diff line change
@@ -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") {
Expand Down Expand Up @@ -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()
Expand All @@ -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";
}

Expand Down Expand Up @@ -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 [];
Expand Down

0 comments on commit 784f4f8

Please sign in to comment.