-
Notifications
You must be signed in to change notification settings - Fork 259
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
Make the global logger thread local #81
Comments
You can pretty easily make a logger that sends its log messages wherever they need to go asynchronously via a background thread, and that fact seems a bit unrelated to whether you then install that logger once globally or explicitly in every thread you spawn. More generally, the log crate used to have a thread local logger, but we explicitly moved away from that in #12. The background is in #3, but the important bit is this:
Systems that want to partition the log data they produce into different places traditionally use something like logback, log4net, etc, that filter based on the "location" the log message is logged to rather than the thread it happens to be running on. An equivalent in the rust world would be something like log4rs. |
Thank you for the reasoned reply - it's much appreciated. I've experimented with a logger that forwards messages. It's a bit clunky for now, but I can see a way through - and it was a useful introduction to Rust's take on thread locals and static initialization. (It'd be nice to have more powerful const functions, but I can see that's being heavily discussed). I'd agree that in the general case, when there is library code that can instantiate threads indirectly, then it's really hard to make a thread-local logger work simply and transparently. The final part of the
Many thanks once again. |
It'd be very useful to have the global logger be init'd so it is thread local. This could be a significant breaking change to library users, so I'd suggest it was done using a compile-time feature.
Why?
thread::mpsc
).What do you think?
The text was updated successfully, but these errors were encountered: