log_macro crates.io

Macro to print variable name and value only (stripped from release builds)

Install

cargo add log_macro

Use

Add this to top of file:

```rust

[macro_use]

extern crate log_macro; ```

Possible uses and outputs:

```rust // print string only log!("hello"); // -> hello

// print variable let animals = vec!["cat", "dog"]; log!(animals); // -> animals: ["cat", "dog"]

// print multiple variables let animals = vec!["cat", "dog"]; let fish = vec!["salmon", "tuna"]; log!(animals, fish); // each variable logged on new line // -> animals: ["cat", "dog"] // -> fish: ["salmon", "tuna"] ```

Implementation

Exported macro code is this:

```rust

[macro_export]

macrorules! log { // Single literal string case ( $val:expr $(,)? ) => {{ if ::std::stringify!($val).startswith("\"") { // Remove quotes for string literals ::std::eprintln!("{}", ::std::stringify!($val).trim_matches('\"')); } else { ::std::eprintln!("{}: {:?}", ::std::stringify!($val), $val); } $val }};

// Multiple variables case
( $($val:expr),+ $(,)? ) => {{
    $(
        $crate::log!($val);
    )+
}};

} ```

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

♥️

Support on GitHub or look into other projects.

MIT Twitter