Skip to content

Logs: the lines before a warning or a crash kept in the log file - #1903

Open
vmillet-dev wants to merge 1 commit into
logs-callsfrom
logs-ring
Open

vmillet-dev wants to merge 1 commit into
logs-callsfrom
logs-ring

Conversation

@vmillet-dev

Copy link
Copy Markdown
Owner

Closes #1845

Stacked on #1902 (each call logged): its base is logs-calls so that this diff is this ticket alone. Merge #1898, #1900, #1901, #1902 in that order; this pull request then targets dev/1.3.3.

A writer of ours, Kept (crates/app/src/logging.rs), wraps flexi_logger's FileLogWriter. Nothing changes for whoever logs.

  • The lines kept. Kept keeps the last 200 lines below what the file keeps, of our crates alone, and only those that passed the levels in force (what the terminal shows). A dependency's lines are never kept, even when DEVNOTES_LOG lets them through: its debug may hold a path or a URL.
  • On a warning or an error, the kept lines are written into the file first, under one line that says how many (— the 37 lines before —, — the line before —), and then emptied. A second warning brings only what came after the first.
  • On a panic, the hook's error line brings the kept lines first, then the hook flushes as before. The hook itself is unchanged; its doc says so. The place is still logged, never the message.
  • How a line is written. Each line is formatted as it comes, with its own time and thread, and the file writer's format is now verbatim: a kept line keeps its time.
  • The e2e flavour keeps nothing aside: its file already keeps every level, so there is never a line below it.
  • Switching or closing a library leaves the kept lines as they are. They say what a line may say (names, codes, durations), and docs/security.md now states what the file may hold and that nothing sealed is in it.
— the 3 lines before —
… INFO  [main] ui::action: #411 Notes::ClearSearch
… INFO  [main] ui::action: #412 Notes::OpenNote
… DEBUG [db] ui::backend: db #412 notes::get 1 ms NoteNotFound
… WARN  [main] ui::services::errors: errors.noteGone: NoteNotFound: …

What our crates log below warn, checked because those lines now reach the file:

Tests (logging::tests; each process run apart has its own logger)

  • a_warning_is_filed_after_the_lines_that_led_to_it_and_the_next_after_those_since: a debug build writes info and debug lines, a warning, an info line, an error, then an info line. The file holds, in order: « the 3 lines before » (« Logging at », the action, the call), the warning, « the line before », the action, the error. The line after the error is not in the file.
  • the_last_two_hundred_lines_are_kept: 250 lines, then a warning. The file holds « the 200 lines before », steps 51 to 250, and not step 50.
  • a_dependency_line_is_never_kept_for_the_file: with DEVNOTES_LOG=debug, a dependency's debug reaches the terminal but not the file; ours does.
  • a_panic_ends_the_process_once_its_place_is_in_the_log: an action line is logged, then the process panics. Its file holds that line, then « Panicked at », and never the message.
  • The existing per-build tests now write their lines below warn after the last warning, so « the file keeps warnings alone » still holds when nothing follows.

Docs. The wiki's logs page gets a new section, « The lines before a warning », and its outputs paragraph points to it. D35's row reads « File: warn and error, after our last 200 lines » and keeps its width. CONTRIBUTING.md and docs/security.md are updated too.

Checks run (Linux)

  • cargo test -p app: 31 + 1 + 1 pass.
  • Journey 01_first_day under Xvfb: green; its debug lines are still in its log.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo fmt --all --check, node scripts/architecture-links.mjs.

Generated by Claude Code

The file's writer is now one of ours, Kept, wrapping flexi_logger's: it
keeps the last 200 lines of our crates below what the file keeps, the
lines the terminal shows under the levels in force, and writes them into
the file before the next warning, error or panic, under one line that
says how many. A second warning brings only what came after the first.
Lines are formatted as they come, time and thread included, and the
file's writer writes them as they are; a dependency's lines are never
kept. The e2e flavour, whose file keeps every level, keeps none.

The panic hook needs no change: its error line brings the ring first.
docs/security.md says what the file may hold; the wiki's logs page, D35
and CONTRIBUTING say it too.

Closes #1845

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BbVs5tCyTr9AasGra3Zzg3

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants