fixes log pagination

This commit is contained in:
Michael Beck
2025-02-05 22:39:10 +01:00
parent 6b57efde79
commit d868a181a9
4 changed files with 35 additions and 13 deletions

11
app.py
View File

@@ -176,7 +176,8 @@ def logs():
@app.route('/logfile', methods=['GET'])
def logfile():
lines = int(request.args.get('lines', 100)) # Number of lines to read
page = int(request.args.get('page', 0)) # Page number
lines_per_page = int(request.args.get('lines_per_page', config['DEFAULT']['LOG_VIEW_LINES'])) # Lines per page
log_file_path = logFile # Path to the current log file
if not os.path.isfile(log_file_path):
@@ -184,8 +185,14 @@ def logfile():
with open(log_file_path, 'r') as file:
log_lines = file.readlines()
log_lines = log_lines[::-1]
return jsonify({"log": log_lines[-lines:]})
start = page * lines_per_page
end = start + lines_per_page
paginated_lines = log_lines[start:end] if start < len(log_lines) else []
return jsonify({"log": paginated_lines, "total_lines": len(log_lines), "pages": len(log_lines) // lines_per_page})
@app.route('/results')
def results():