feat: Limit log display to 20 latest entries, newest first

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
Chris Frankland-Wright 2025-08-08 00:23:32 +01:00
parent 463856a330
commit adae9026ad

View file

@ -291,18 +291,20 @@ document.addEventListener('DOMContentLoaded', () => {
async function fetchLogs() { async function fetchLogs() {
if (useMockData) { if (useMockData) {
const logs = mockApiDataSets[currentMockSetKey].logs; // Use a copy to avoid mutating the original mock data array
statusElements.logs.textContent = logs.join('\n'); const logs = mockApiDataSets[currentMockSetKey].logs.slice();
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');
return; return;
} }
try { try {
const response = await fetch('/api/logs'); const response = await fetch('/api/logs');
if (!response.ok) throw new Error('Failed to fetch logs'); if (!response.ok) throw new Error('Failed to fetch logs');
const logs = await response.json(); const logs = await response.json();
statusElements.logs.textContent = logs.join('\n'); // Show latest 20 logs, with the newest at the top.
// Auto-scroll to the bottom logs.reverse();
statusElements.logs.scrollTop = statusElements.logs.scrollHeight; statusElements.logs.textContent = logs.slice(0, 20).join('\n');
} catch (error) { } catch (error) {
console.error('Error fetching logs:', error); console.error('Error fetching logs:', error);
statusElements.logs.textContent = 'Error fetching logs.'; statusElements.logs.textContent = 'Error fetching logs.';