From adae9026ad2cdfd068c70cd4e4b50e039e73ea12 Mon Sep 17 00:00:00 2001 From: Chris Frankland-Wright Date: Fri, 8 Aug 2025 00:23:32 +0100 Subject: [PATCH] feat: Limit log display to 20 latest entries, newest first Co-authored-by: aider (gemini/gemini-2.5-pro) --- static/script.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/static/script.js b/static/script.js index 9bbf08b..4b37c63 100644 --- a/static/script.js +++ b/static/script.js @@ -291,18 +291,20 @@ document.addEventListener('DOMContentLoaded', () => { async function fetchLogs() { if (useMockData) { - const logs = mockApiDataSets[currentMockSetKey].logs; - statusElements.logs.textContent = logs.join('\n'); - statusElements.logs.scrollTop = statusElements.logs.scrollHeight; + // Use a copy to avoid mutating the original mock data array + const logs = mockApiDataSets[currentMockSetKey].logs.slice(); + // Show latest 20 logs, with the newest at the top. + logs.reverse(); + statusElements.logs.textContent = logs.slice(0, 20).join('\n'); return; } try { const response = await fetch('/api/logs'); if (!response.ok) throw new Error('Failed to fetch logs'); const logs = await response.json(); - statusElements.logs.textContent = logs.join('\n'); - // Auto-scroll to the bottom - statusElements.logs.scrollTop = statusElements.logs.scrollHeight; + // Show latest 20 logs, with the newest at the top. + logs.reverse(); + statusElements.logs.textContent = logs.slice(0, 20).join('\n'); } catch (error) { console.error('Error fetching logs:', error); statusElements.logs.textContent = 'Error fetching logs.';