Group logs based on timestamp

This commit is contained in:
Nicolas Mowen 2024-04-03 10:00:04 -06:00
parent f98b0ee6f0
commit 974ae1907a
2 changed files with 39 additions and 18 deletions

View File

@ -9,14 +9,7 @@ from datetime import datetime, timedelta
from functools import reduce from functools import reduce
import requests import requests
from flask import ( from flask import Blueprint, Flask, current_app, jsonify, make_response, request
Blueprint,
Flask,
current_app,
jsonify,
make_response,
request,
)
from markupsafe import escape from markupsafe import escape
from peewee import operator from peewee import operator
from playhouse.sqliteq import SqliteQueueDatabase from playhouse.sqliteq import SqliteQueueDatabase
@ -159,9 +152,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)
@ -433,9 +426,37 @@ def logs(service: str):
contents = file.read() contents = file.read()
file.close() file.close()
lines = contents.splitlines() # use the start timestamp to group logs together``
logLines = []
keyLength = 0
dateEnd = 0
currentKey = ""
currentLine = ""
for rawLine in contents.splitlines():
cleanLine = rawLine.strip()
if len(cleanLine) < 10:
continue
if dateEnd == 0:
dateEnd = cleanLine.index(" ")
keyLength = dateEnd - (6 if service_location == "frigate" else 0)
newKey = cleanLine[0:keyLength]
if newKey == currentKey:
currentLine += f"\n{cleanLine[dateEnd:].strip()}"
continue
else:
logLines.append(currentLine)
currentKey = newKey
currentLine = cleanLine
logLines.append(currentLine)
return make_response( return make_response(
jsonify({"totalLines": len(lines), "lines": lines[start:end]}), jsonify({"totalLines": len(logLines), "lines": logLines[start:end]}),
200, 200,
) )
except FileNotFoundError as e: except FileNotFoundError as e:

View File

@ -246,11 +246,6 @@ function Logs() {
return; return;
} }
if (logLines.length < 100) {
setInitialScroll(true);
return;
}
if (initialScroll) { if (initialScroll) {
return; return;
} }
@ -259,6 +254,11 @@ function Logs() {
return; return;
} }
if (contentRef.current.scrollHeight <= contentRef.current.clientHeight) {
setInitialScroll(true);
return;
}
contentRef.current?.scrollTo({ contentRef.current?.scrollTo({
top: contentRef.current?.scrollHeight, top: contentRef.current?.scrollHeight,
behavior: "instant", behavior: "instant",