grouped container logs now show one merged timeline sorted by time

This commit is contained in:
jarek committed 2026-08-14 09:35:37 +02:00
1 parent a89a6e3bd4
commit a38e973155
2 files changed
+43 -6

No files matched your search

+14 -6
View File
@@ -21,7 +21,7 @@ import type { FavoriteGroup } from '../api/preferences/favorite-groups/+server';
import { currentEnvironment, environments, appendEnvParam } from '$lib/stores/environment';
import { appSettings, formatLogTimestamps } from '$lib/stores/settings';
import { NoEnvironment } from '$lib/components/ui/empty-state';
import { parseLines, renderLineHtml, type LogEntry } from '$lib/utils/log-entry';
import { parseLines, renderLineHtml, sortByTimestampStable, type LogEntry } from '$lib/utils/log-entry';
function renderTimestamp(ts: string | undefined): string {
if (!ts) return '';
@@ -165,14 +165,19 @@ import type { FavoriteGroup } from '../api/preferences/favorite-groups/+server';
queueMicrotask(flushGroupedLogs);
}
function flushGroupedLogs() {
// initial=true is the tail flush: sort the whole buffer by timestamp so the
// history reads as one timeline regardless of per-container arrival order
// (#1406). Live flushes append in arrival order (already chronological) to
// avoid new lines jumping into the middle of the view.
function flushGroupedLogs(initial = false) {
groupedFlushScheduled = false;
if (pendingGroupedEntries.length === 0) return;
const maxLines = getMaxLines();
const incoming = pendingGroupedEntries.length > maxLines
? pendingGroupedEntries.slice(pendingGroupedEntries.length - maxLines)
: pendingGroupedEntries;
mergedLogs = compact([...mergedLogs, ...incoming], maxLines);
const combined = [...mergedLogs, ...incoming];
mergedLogs = compact(initial ? sortByTimestampStable(combined) : combined, maxLines);
pendingGroupedEntries = [];
scrollToBottom();
}
@@ -999,7 +1004,10 @@ import type { FavoriteGroup } from '../api/preferences/favorite-groups/+server';
if (data.logs) {
const { entries } = parseLines(data.logs, '', { containerId, containerName, color });
mergedLogs = compact([...mergedLogs, ...entries], getMaxLines());
// Stopped logs are historical: sort the merged buffer by timestamp so
// each container's block interleaves into one timeline instead of being
// appended as a separate per-container chunk (#1406).
mergedLogs = compact(sortByTimestampStable([...mergedLogs, ...entries]), getMaxLines());
}
} catch (error) {
console.error(`Failed to fetch logs for stopped container ${containerId}:`, error);
@@ -1097,7 +1105,7 @@ import type { FavoriteGroup } from '../api/preferences/favorite-groups/+server';
initialBuffering = false;
initialBufferTimeout = null;
loading = false;
flushGroupedLogs();
flushGroupedLogs(true);
}, INITIAL_BUFFER_DELAY);
});
@@ -1153,7 +1161,7 @@ import type { FavoriteGroup } from '../api/preferences/favorite-groups/+server';
initialBufferTimeout = null;
}
loading = false;
flushGroupedLogs();
flushGroupedLogs(true);
}
});