fix: harden application log viewer
Add an Application Logs window backed by a bounded persistent main log file. The viewer loads history from lanspread.log, subscribes to live INFO/WARN/ERROR log events, supports filtering/copy/pause controls, and keeps the menu/window routing separate from the unpack log viewer. The backend sink now owns serialized access to the log file. History reads and append-time trimming use the same sink lock, so opening the logs window cannot race with a concurrent write and rewrite away a freshly appended line. The sink also keeps a persistent file handle instead of reopening the file for each captured event. Live log events carry sink-local sequence ids. The frontend uses the history watermark plus returned history line counts to suppress live events that were already included in the history response, while preserving buffered rows that were trimmed out of the history file. Auto-scroll now follows the last visible row identity, so it continues following after the in-memory cap keeps the row count stable. No timestamp code change was needed. On the Linux dev host, a temporary probe showed time::OffsetDateTime::now_local() returning +02:00 while UTC was +00:00, matching the host CEST offset. Test Plan: - just fmt - just frontend-test - just test - just clippy - just build - git diff --cached --check - temporary Linux probe of OffsetDateTime::now_local() showed local +02:00 Refs: none
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import {
|
||||
dedupeBufferedRows,
|
||||
lineCountsFromRows,
|
||||
rowFromPayload,
|
||||
rowsFromHistory,
|
||||
rowWasLoadedInHistory,
|
||||
} from '../src/lib/mainLogs.ts';
|
||||
|
||||
const assertEquals = <T>(actual: T, expected: T, message: string) => {
|
||||
if (actual !== expected) {
|
||||
throw new Error(`${message}: expected ${expected}, got ${actual}`);
|
||||
}
|
||||
};
|
||||
|
||||
Deno.test('history rows parse levels and stable ids', () => {
|
||||
const rows = rowsFromHistory('[2026-06-07][12:00:00][app][WARN] careful\nplain line\n');
|
||||
|
||||
assertEquals(rows.length, 2, 'history should skip trailing empty line');
|
||||
assertEquals(rows[0].id, 'history-0', 'history id should include row position');
|
||||
assertEquals(rows[0].level, 'WARN', 'explicit level should be parsed');
|
||||
assertEquals(rows[1].level, 'INFO', 'unknown level should default to info');
|
||||
});
|
||||
|
||||
Deno.test('buffered main log rows covered by history sequence are removed', () => {
|
||||
const historyRows = rowsFromHistory('[2026-06-07][12:00:01][app][INFO] included\n');
|
||||
const included = rowFromPayload({
|
||||
line: '[2026-06-07][12:00:01][app][INFO] included',
|
||||
level: 'INFO',
|
||||
sequence: 4,
|
||||
});
|
||||
const fresh = rowFromPayload({
|
||||
line: '[2026-06-07][12:00:02][app][INFO] fresh',
|
||||
level: 'INFO',
|
||||
sequence: 5,
|
||||
});
|
||||
|
||||
const deduped = dedupeBufferedRows(lineCountsFromRows(historyRows), [included, fresh], 4);
|
||||
|
||||
assertEquals(rowWasLoadedInHistory(included, 4), true, 'included row should match history');
|
||||
assertEquals(deduped.length, 1, 'only fresh row should remain');
|
||||
assertEquals(deduped[0].line, fresh.line, 'fresh row should not be dropped');
|
||||
});
|
||||
|
||||
Deno.test('buffered rows missing from trimmed history are retained', () => {
|
||||
const retained = rowFromPayload({
|
||||
line: '[2026-06-07][12:00:00][app][INFO] trimmed out',
|
||||
level: 'INFO',
|
||||
sequence: 2,
|
||||
});
|
||||
|
||||
const deduped = dedupeBufferedRows(new Map(), [retained], 4);
|
||||
|
||||
assertEquals(deduped.length, 1, 'trimmed row should remain visible');
|
||||
assertEquals(deduped[0].line, retained.line, 'trimmed row should be preserved');
|
||||
});
|
||||
Reference in New Issue
Block a user