Conversation
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #57.
As I said in the issue, I moved the logging to
tracing+tracing-subscriber, soRUST_LOGworks like in any other Rust program:
The old
App::log()pushed aStringintoapp.logs, andgoto()called it on every cursormovement, so the vector grew for the whole session and the window was mostly a wall of
goto: 2alines. There were no levels either, so a failure looked exactly like a cursor move,and there was no way to get any of it out of the process.
Now the messages go to two places. The window (
Alt+l) reads a ring buffer with the last 2048of them. They also go to
stderr, but only when you redirect it, because the TUI owns theterminal and writing there would mess up the screen:
When
stderris the terminal, the messages stay in the buffer and are printed after theterminal is restored: warnings and errors only, or everything, if you set
RUST_LOGyourself.So
dz6 file.binstays as quiet as before, butRUST_LOG=debug dz6 file.binstill gives youthe whole log when you quit. It works after a panic too: our hook is installed before
ratatui::init(), so ratatui restores the terminal, the default hook prints the panic, andthen the log comes out.
This is what the window looks like with
RUST_LOG=debug, after a search:Without
RUST_LOGthe same window shows three lines (started, file loaded, database loaded),which is about what it showed before, so I think the default (
warn,dz6=info) is a good one.gotois attracelevel now, and it carriespage_startandpage_end, which is theinformation the window used to print as a
{:?}ofReaderat the top.The window itself got a bit better while I was there: it shows the time, level, module and the
span of each message, colors the level with the terminal colors (so it works in both themes),
opens on the newest message, and scrolls with
j/k,f/b,g/Gandh/l.cclearsit. I dropped the line wrapping in exchange for an exact scroll limit (the old one incremented
the offset forever, even past the end) and for building only the lines that are visible instead
of all of them. Long lines scroll sideways now.
I added three tests in
src/logging.rs: the buffer dropping the oldest messages, an invalidRUST_LOGfalling back to the default, and an event becoming a record.cargo fmtandcargo clippyare clean, the two warnings left were already there before this PR.A little on how it looks:
New dependencies:
tracingandtracing-subscriber(with theenv-filterfeature).