-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add a log callback that takes a formatted message. #802
Conversation
In some contexts (e.g. cubeb-rs), it is not possible to pass a method that formats a string (for instance, because `c_variadic` is not stable in rust, and because it only supports compile-time constant format strings). So, add a callback method that takes a `const char*` that has already been printf-style formatted.
cfd4554
to
758065c
Compare
cc @padenot :) |
This depends on mozilla/cubeb#802.
gentle ping on this :) |
I don't remember exactly how we set things up, aren't the macros exposed on the rust side as well? There's a bit of custom code for rust. |
This is for capturing logs and saving them to output, rather than adding to logs. I do not see anything in cubeb-rs right now that turns on logs (https://github.com/search?q=repo%3Amozilla%2Fcubeb-rs%20cubeb_set_log_callback&type=code or https://docs.rs/cubeb/latest/cubeb/), but if I'm missing something pointers would be appreciated! |
The problem I'm trying to solve is that https://docs.rs/cubeb/latest/cubeb/ffi/fn.cubeb_set_log_callback.html is not really usable for the reasons mentioned in the original comment: the lack of c_variadic, the requirement for compile-time constant format strings, plus also the fact that rust does not use C format string syntax. For additional context, see the proposed usage of this in cubeb-rs here: https://github.com/mozilla/cubeb-rs/pull/98/files |
If you'd like to have a log with variadic parameters, something like this should work: mozilla/cubeb-coreaudio-rs@1524600 |
I don't believe that that does what I want, as my ultimate goal is to be able to write the logs from cubeb to the same file as those for the rest of my library, using rust's logging macros, rather than just to write them to stdout (or even any specific fd). If I just wrote the logs to an fd, they would be out-of-order with the messages that go through rust's logging macros. If it were possible to use something like mozilla/cubeb-coreaudio-rs@1524600 to generate a |
though, I suppose i could write an |
Thanks for the pointer, I was able to make this work in mozilla/cubeb-rs#98 without any changes to cubeb. |
In some contexts (e.g. cubeb-rs), it is not possible to pass a method that formats a string (for instance, because
c_variadic
is not stable in rust, and because it only supports compile-time constant format strings).So, add a callback method that takes a
const char*
that has already been printf-style formatted.