Refines log reader to read only X last lines for faster log reading. Adds config for log reading.

This commit is contained in:
Michael Beck
2025-02-05 23:31:23 +01:00
parent d868a181a9
commit 3282270164
3 changed files with 86 additions and 15 deletions

View File

@@ -6,10 +6,18 @@ document.addEventListener('DOMContentLoaded', () => {
const nextPageButton = document.getElementById('nextPage');
const pageInfo = document.getElementById('pageInfo');
let currentPage = 0;
const linesPerPage = 50;
let linesPerPage;
let autoRefreshInterval;
// Fetch the configuration value for linesPerPage
fetch('/config/lines_per_page')
.then(response => response.json())
.then(data => {
linesPerPage = data.lines_per_page;
// Initial fetch of logs after getting the config value
fetchLogs(currentPage);
});
const fetchLogs = (page) => {
fetch(`/logfile?page=${page}&lines_per_page=${linesPerPage}`)
.then(response => response.json())
@@ -18,7 +26,7 @@ document.addEventListener('DOMContentLoaded', () => {
logsElement.textContent = data.error;
} else {
logsElement.innerHTML = data.log.map((line, index) => {
const lineNumber = data.total_lines - (page * linesPerPage + index);
const lineNumber = data.start_line - index;
return `<span class="line-number">${lineNumber}</span> ${line}`;
}).join('');
// Disable/enable pagination buttons based on the page number and total lines
@@ -29,11 +37,11 @@ document.addEventListener('DOMContentLoaded', () => {
});
};
const startAutoRefresh = () => {
function startAutoRefresh() {
autoRefreshInterval = setInterval(() => {
fetchLogs(currentPage);
}, 5000); // Refresh every 5 seconds
};
}
const stopAutoRefresh = () => {
clearInterval(autoRefreshInterval);