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

View File

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

View File

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