Support log data format

This commit is contained in:
Nicolas Mowen 2024-04-03 06:13:55 -06:00
parent a77efde0da
commit c6d937cec0
3 changed files with 26 additions and 16 deletions

View File

@ -159,9 +159,9 @@ def config():
config["plus"] = {"enabled": current_app.plus_api.is_active()}
for detector, detector_config in config["detectors"].items():
detector_config["model"]["labelmap"] = (
current_app.frigate_config.model.merged_labelmap
)
detector_config["model"][
"labelmap"
] = current_app.frigate_config.model.merged_labelmap
return jsonify(config)
@ -425,11 +425,19 @@ def logs(service: str):
404,
)
start = request.args.get("start", type=int, default=0)
end = request.args.get("start", type=int)
try:
file = open(service_location, "r")
contents = file.read()
file.close()
return contents, 200
lines = contents.splitlines()
return make_response(
jsonify({"totalLines": len(lines), "lines": lines[start:end]}),
200,
)
except FileNotFoundError as e:
logger.error(e)
return make_response(

View File

@ -1,6 +1,6 @@
import { Button } from "@/components/ui/button";
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";
import { LogLine, LogSeverity } from "@/types/log";
import { LogData, LogLine, LogSeverity } from "@/types/log";
import copy from "copy-to-clipboard";
import { useCallback, useMemo, useRef, useState } from "react";
import { IoIosAlert } from "react-icons/io";
@ -23,13 +23,13 @@ const ngSeverity = /(GET)|(POST)|(PATCH)|(DELETE)/;
function Logs() {
const [logService, setLogService] = useState<LogType>("frigate");
const { data: frigateLogs } = useSWR<string>("logs/frigate", {
const { data: frigateLogs } = useSWR<LogData>("logs/frigate", {
refreshInterval: 1000,
});
const { data: go2rtcLogs } = useSWR<string>("logs/go2rtc", {
const { data: go2rtcLogs } = useSWR<LogData>("logs/go2rtc", {
refreshInterval: 1000,
});
const { data: nginxLogs } = useSWR<string>("logs/nginx", {
const { data: nginxLogs } = useSWR<LogData>("logs/nginx", {
refreshInterval: 1000,
});
@ -43,7 +43,7 @@ function Logs() {
} else if (logService == "nginx") {
return nginxLogs;
} else {
return "unknown logs";
return undefined;
}
}, [logService, frigateLogs, go2rtcLogs, nginxLogs]);
@ -53,8 +53,7 @@ function Logs() {
return [];
}
return frigateLogs
.split("\n")
return frigateLogs.lines
.map((line) => {
const match = frigateDateStamp.exec(line);
@ -89,8 +88,7 @@ function Logs() {
return [];
}
return go2rtcLogs
.split("\n")
return go2rtcLogs.lines
.map((line) => {
if (line.length == 0) {
return null;
@ -130,8 +128,7 @@ function Logs() {
return [];
}
return nginxLogs
.split("\n")
return nginxLogs.lines
.map((line) => {
if (line.length == 0) {
return null;
@ -152,7 +149,7 @@ function Logs() {
const handleCopyLogs = useCallback(() => {
if (logs) {
copy(logs);
copy(logs.lines.join("\n"));
}
}, [logs]);

View File

@ -1,3 +1,8 @@
export type LogData = {
lineCount: number;
lines: string[];
};
export type LogSeverity = "info" | "warning" | "error" | "debug";
export type LogLine = {