fixes log pagination
This commit is contained in:
11
app.py
11
app.py
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user