-
Notifications
You must be signed in to change notification settings - Fork 95
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
term::TermDecorator
should do line buffering
#125
Comments
Agreed. Though I was wondering if this should be decorator's job, or the IO given to decorator should do it. One can just wrap the io in https://doc.rust-lang.org/std/io/struct.BufWriter.html. |
Oh, you are already doing it but though it's tricky with |
Please not however that on Windows colors and other decoration are separate calls and the data is not being sent in-line as escape codes, so it can't be buffered, AFAIK. |
It should be possible to buffer the evaluation of the format string on Windows though, removing this kind of call:
(prints the current time). |
Oh dear. This is https://github.com/slog-rs/term/blob/12f4e905af008a666c5e0dda1cd1b362ae7061e9/src/lib.rs#L773 . Very inefficient. Do you think you can come up with a PR? Since you have all the instrumentation there, maybe you can come up with best layer to stuff buffering there. |
I made an issue in the |
Another argument for line buffering is that when interleaved with other logging systems (GStreamer with lots of threads in my case) I often see line-buffered output of those interleaved with parts of slog output. Makes it really hard to work with when it happens. |
I absolutely agree that slog-term should do line buffering. However, I would like to note that any buffering beyond that should be configurable and off by default. I use slog-term for debugging crates that use unsafe code. It's important that I see each line as soon as it happens in case my app crashes. I remember being bitten by a nasty bug because I buffered over multiple lines when logging to a file. Flushing after every newline fixed it. I just want to make sure that doesn't happen to new users 😉 EDIT: Just realized this issue is old. Is this still a problem? |
term::TermDecorator
could be fasterterm::TermDecorator
should do line buffering
Seems like it's open, so no one produced a PR. At this point I'm only merging things that other people are willing to put an effort into. :) |
term::TermDecorator
could be faster on Linux by line-buffering its output instead of outputting many parts of the line with their own syscall.Diff I applied to the
term
crate (notslog-term
!):I used the following program to check how fast a logging statement is:
strace without optimization:
strace with optimization:
Without the optimization, it ran in 11.6 seconds, with the optimization, it ran it 4.5 seconds.
The text was updated successfully, but these errors were encountered: