mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
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:
parent
463856a330
commit
adae9026ad
1 changed files with 8 additions and 6 deletions
|
|
@ -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.';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue