Skip to content
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 ldbg! macro that mirrors std::dbg #546

Open
tgross35 opened this issue Mar 3, 2023 · 1 comment
Open

Add a ldbg! macro that mirrors std::dbg #546

tgross35 opened this issue Mar 3, 2023 · 1 comment

Comments

@tgross35
Copy link

tgross35 commented Mar 3, 2023

The std::dbg!() macro is quite useful for quick debugging. I have stumbled across at least a handful of cases where whatever the logger is is more useful than stderr output - for example, when the logger is mapped to RTT or UART on embedded and there is no stderr available.

So, my suggestion is to add ldbg that acts similarly to the debug macro, but uses the default logger.

use log::{ldbg, Level};

let v = vec![0usize, 1, 2, 3, 4];

// default to debug level (possibly warn or info so it's more likely to show up)
let m = ldbg!(&v[2..]);

// allow for optional level override
let n = ldbg!(level: Level::Warn, &v[..3]);
@Thomasdezeeuw
Copy link
Collaborator

I'm on the fence on this.

On the one hand I see the usefulness of the dbg! macro for quick debugging. However I think these statement shouldn't be committed (i.e. they should be removed before sending the code upstream).

If you need more information in a way that the log crate can provide I think it would be more beneficial to add proper debug! message and use the release_max_level_info (or similar) feature to remove them from release binary. (this will also safe you time the next time you're debugging a similar issue, speaking from experience)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants