mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-05-21 01:16:37 +02:00
parent
d93d6262ce
commit
dd7fd16b69
@ -12,5 +12,5 @@ export type LogLine = {
|
|||||||
content: string;
|
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];
|
export type LogType = (typeof logTypes)[number];
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
import { LogLine, LogSeverity, LogType } from "@/types/log";
|
import { LogLine, LogSeverity, LogType } from "@/types/log";
|
||||||
|
|
||||||
|
const pythonSeverity = /(DEBUG)|(INFO)|(WARNING)|(ERROR)/;
|
||||||
|
|
||||||
const frigateDateStamp = /\[[\d\s-:]*]/;
|
const frigateDateStamp = /\[[\d\s-:]*]/;
|
||||||
const frigateSeverity = /(DEBUG)|(INFO)|(WARNING)|(ERROR)/;
|
|
||||||
const frigateSection = /[\w.]*/;
|
const frigateSection = /[\w.]*/;
|
||||||
|
|
||||||
const goSeverity = /(DEB )|(INF )|(WRN )|(ERR )/;
|
const goSeverity = /(DEB )|(INF )|(WRN )|(ERR )/;
|
||||||
const goSection = /\[[\w]*]/;
|
const goSection = /\[[\w]*]/;
|
||||||
|
|
||||||
const ngSeverity = /(GET)|(POST)|(PUT)|(PATCH)|(DELETE)/;
|
const httpMethods = /(GET)|(POST)|(PUT)|(PATCH)|(DELETE)/;
|
||||||
|
|
||||||
export function parseLogLines(logService: LogType, logs: string[]) {
|
export function parseLogLines(logService: LogType, logs: string[]) {
|
||||||
if (logService == "frigate") {
|
if (logService == "frigate") {
|
||||||
@ -45,7 +46,7 @@ export function parseLogLines(logService: LogType, logs: string[]) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
dateStamp: match.toString().slice(1, -1),
|
dateStamp: match.toString().slice(1, -1),
|
||||||
severity: frigateSeverity
|
severity: pythonSeverity
|
||||||
.exec(line)
|
.exec(line)
|
||||||
?.at(0)
|
?.at(0)
|
||||||
?.toString()
|
?.toString()
|
||||||
@ -69,7 +70,7 @@ export function parseLogLines(logService: LogType, logs: string[]) {
|
|||||||
let section =
|
let section =
|
||||||
goSection.exec(line)?.toString()?.slice(1, -1) ?? "startup";
|
goSection.exec(line)?.toString()?.slice(1, -1) ?? "startup";
|
||||||
|
|
||||||
if (frigateSeverity.exec(section)) {
|
if (pythonSeverity.exec(section)) {
|
||||||
section = "startup";
|
section = "startup";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,11 +123,51 @@ export function parseLogLines(logService: LogType, logs: string[]) {
|
|||||||
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: httpMethods.exec(line)?.at(0)?.toString() ?? "META",
|
||||||
content: line.substring(line.indexOf(" ", 20)).trim(),
|
content: line.substring(line.indexOf(" ", 20)).trim(),
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter((value) => value != null) as LogLine[];
|
.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 [];
|
return [];
|
||||||
|
Loading…
Reference in New Issue
Block a user