-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Avoid other output between contents when printing #786
Conversation
This makes sure the OutWriter writes the newline as part of the same buffer as the output. This makes it less likely that the output will be interrupted between the content and the newline. E.g. without this and enabling logging, log messages will be injected between the content and the newline, making the output garbled. Unfortunately this isn't entirely correct and is more of a heuristic because most of our output is small enough that they fit in a single write. In the blocking world you'd lock Stderr while printing the messages, in the tokio world however I don't know how to safely do this.
src/main.rs
Outdated
@@ -99,8 +99,9 @@ impl OutWriter { | |||
impl OutWriter { | |||
pub async fn println(&self, content: impl AsRef<[u8]>) { | |||
let stderr = &mut *self.stderr.lock().await; | |||
stderr.write_all(content.as_ref()).await.unwrap(); | |||
stderr.write_all(b"\n").await.unwrap(); | |||
let mut buf: Vec<u8> = content.as_ref().to_vec(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
much allocations :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, agreed. But this isn't very critical. We don't output much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think you could the signature to take a String
and just extend that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's nicer indeed. done
All logging is already to stderr with the content going to stdout, so I am not really convinced this is something we need to be concerned with. |
Yes, this is purely user experience: both our logging and tracing logging interact currently. E.g.
Notice how the ticket and the tracing output just run into each other. Some users will not realise where one stops and the other starts. That's what I'm trying to fix. With this fix you get:
Which is a lot better. |
looking at this the ticket and other info should go to stdout I think |
I think that's orthogonal though, it still is printed to the same terminal by default so it still can end up mangled in the output without locking or otherwise figuring out how to sequence these writes. |
Allocations still depends on how format! allocates
Why do we have this |
This makes sure the OutWriter writes the newline as part of the same
buffer as the output. This makes it less likely that the output will
be interrupted between the content and the newline. E.g. without this
and enabling logging, log messages will be injected between the
content and the newline, making the output garbled.
Unfortunately this isn't entirely correct and is more of a heuristic
because most of our output is small enough that they fit in a single
write. In the blocking world you'd lock Stderr while printing the
messages, in the tokio world however I don't know how to safely do
this.