-
Notifications
You must be signed in to change notification settings - Fork 717
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
Clarify whether logging to standard output is blocking #668
Comments
Hi @ufoscout, thanks for the question! In both In the example you posted, Even though it makes blocking calls, the performance impact of this approach shouldn't be too significant, even in asynchronous code. Issues with blocking in async programs generally arise when a thread is blocked for a relatively long period of time,and short blocking operations are generally fine. We chose this as the default behavior because non-blocking logging would introduce additional complexity — a dedicated logging thread or async task would need to be spawned, and users would need to ensure that logs are flushed when the program exits. Non-blocking logging is theoretically superior, but the difference is probably only meaningful in particularly performance-sensitive code. And, a naive implementation where Since the writer used to output formatted logs can be overridden by the user, though, it's definitely possible to supply one that's non-blocking. We don't currently provide a ready-made non-blocking writer, but adding an implementation is on my todo list. It isn't done yet mainly because I want to ensure we do it right and avoid the allocator pressure I mentioned previously. Hope that answers your questions? |
@hawkw |
@ufoscout will do! And, if you like, I can ping you when the dedicated logging thread/task stuff is ready. |
@hawkw |
Another update: thanks to @zekisherif, we've just merged #673, with an initial version of a It still needs additional documentation & polish before it's ready to release, but if you're interested you can start trying it out now! |
Hi! I would like to revive this issue because I was just bitten very very hard by the blocking calls. When setting up It is very important to avoid new users to fall into the same frustrating trap. I suggest a disclaimer in the tracing_subscriber::fmt docs that warns users about this and points users to But I'm not sure that would be sufficient. You usually integrate your logging at the very beginning of a project, and the blocking might kick in months later. Is there really no way to warn users when it occurs? |
I cannot find in the documentation a clear statement about the eventual blocking nature of logging to the standard output.
Could you please help me understand if in the following example there is blocking code in an async function?
The text was updated successfully, but these errors were encountered: