-
Notifications
You must be signed in to change notification settings - Fork 258
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 pub "-v" macros for inline expression logging #316
Conversation
The `std::dbg!` macro from which this was inpsured, was only just introduced in rust 1.32, but this just relies upon the `core` or `std` `stringify` macro, which is "since 1.0.0" Includes doctests and an external no-harness test. Works with or without _std_, per testing.
Hi @dekellum 👋 This is a neat idea! I'm not sure we need to provide it directly in |
Edit: The below rationale is largely superseded by RFC #317. Fair point. May I offer a rationale for including these macros here in BackgroundThe In an executable project where configuring
Indeed, a major point of the Its seems to follow that for executable projects that do already have However, Why add this to
|
Thanks for your thoughts @dekellum! This is something that should be possible to support using structured logging (that would be preferable over interpolation into the message), however that would probably require some breakage. I think the issue of discoverability is a little different for Combined with additional freedom to iterate on the API (I can imagine requests for |
Just a follow-up: I think your rationale is fair and thorough, and that this is something we should support somehow, I just feel like we need to give it time and space to iterate before committing to new API in |
I think its fair that you would want any public macro additions to be good and as stable as possible before adding to Adding the remaining levels for the feature is reasonable, though it goes beyond strict parity with Would you entertain a hopefully mini-RFC just focusing on the potential API additions? That discussion would be neutral to the |
That sounds like a good idea! |
debugv
and tracev
macros for inline expression logging
Would someone in the know, like @dtolnay, be able to review the macro additions specifically? I feel like I'm still a |
I am an unpaid amateur too but this didn't work for me: use log::{logv, Level};
fn main() {
logv!(Level::Debug, 0);
} error: cannot find macro `__logv!` in this scope
--> src/main.rs:4:5
|
4 | logv!(Level::Debug, 0);
| ^^^^^^^^^^^^^^^^^^^^^^^ help: you could try the macro: `logv`
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
warning: unused import: `Level`
--> src/main.rs:1:17
|
1 | use log::{logv, Level};
| ^^^^^
|
= note: #[warn(unused_imports)] on by default |
Oh boy, that's embarrassing as it seems like something my tests should have caught, since they do test edit: I will write another 2018 specific test, in any case, thanks! |
It was simpler then that—I had just missed specifying the One related item I'm not sure on is that, currently, the (1) I hadn't fully internalized that there are were no tests currently in log, that actually test 2018-edition style macro import. That could be fixed, likely best as a follow-on PR so as to include all existing public macros. |
The implementation looks correct now. (Note: I only looked at the new macro_rules macros in src/macros.rs, not any of the other changes.) I am not yet sold on adding all these macros. I left a comment on the RFC PR since that seems the more appropriate place for that discussion. |
These new macro's were inspired by
std::dbg!
(just released in rust 1.32). Usage is the same, but these send output to the log instead of stderr, at theDebug
orTrace
level. Onlystd::stringify
orcore::stringify
is required for the implementation, so this doesn't increase MSRV as these are "since 1.0.0".Includes doctests and an external no-harness test.
Works with or without std, per testing.