log_macro
Macro to print variable(s) with values nicely (stripped from release builds)
Install
cargo add log_macro
Use
Add this to top of file:
extern crate log_macro;
Possible uses and outputs:
// print string only
log!; // -> hello
// print variable
let animals = vec!;
log!; // -> animals: ["cat", "dog"]
// print multiple variables
let animals = vec!;
let fish = vec!;
log!;
// each variable logged on new line
// -> animals: ["cat", "dog"]
// -> fish: ["salmon", "tuna"]
Variables will be in green color to stand out.
Implementation
Exported macro code is this:
Run
Will run the tests in src/lib.rs.
cargo watch -q -- sh -c "tput reset && cargo test -q --lib"
Contribute
The tasks to do are outlined in existing issues and in tasks below (sorted by priority).
If issue/idea you have is not there, open new issue or start discussion.
Any PR with code/doc improvements is welcome. ✨
Join Discord for more indepth discussions on this repo and others.
Tasks
- fix docset for the macro export, nothing is showing
- there are some errors present after running
cargo test --doc --package log_macro -- log --nocapture. fix them
- there are some errors present after running
- fix the tests
- currently they fail as I am not sure how to actually test that the logs are as they are
- GPT says to try use duct potentially but that gave some issues
- add support for multiple values or different ways of formatting
- not sure what author meant, investigate
- get the same level of utilities that Python’s formatted string literals have
> print(f”operation: {2+1=}”)->operation: 2+1=3
- decide if macro should be stripped from release builds or not
- currently it's stripped similar to
dbg! - potentially provide another near identical macro to keep similar logs but also in release mode?
- currently it's stripped similar to
♥️
Support on GitHub or look into other projects.