#debugging #verbose #verbose-macros #debug-macro #verbose-macro

verbose-macros

A dependency-free macro library for verbose! and debug! printing in Rust

2 releases

Uses new Rust 2024

new 0.1.1 May 11, 2025
0.1.0 May 11, 2025

#278 in Configuration

36 downloads per month

MIT license

10KB
77 lines

Verbose Macros

license-mit ci state Conventional Commits

Rust crate Rust documentation

A dependency-free macro library for verbose! and debug! printing in Rust.

Introduction

I usually use log with all log levels for printing, but some people prefer to use just the --verbose and --debug flags.

For this reason, I created this library to provide a simple way to print verbose and debug messages without the need for any dependencies or setup to the log crate.

The library just provides the verbose! and debug! macros, which have the same syntax as println! and prints only if the flags for them are set.

Get Started

Add the following to your Cargo.toml:

[dependencies]
verbose-macros = "0.1"

Then, you can use the macros in your code:

use verbose_macros::{debug, verbose};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let verbose = std::env::args().any(|arg| arg == "--verbose" || arg == "-v");
    let debug = std::env::args().any(|arg| arg == "--debug" || arg == "-d");

    // Set the debug and verbose flags
    verbose_macros::set_debug(verbose);
    verbose_macros::set_verbose(debug);

    // Use the debug macro
    debug!("This is a debug message.");
    debug!("This is a debug message with a value: {}", 42);

    // Use the verbose macro
    verbose!("This is a verbose message.");
    verbose!("This is a verbose message with a value: {}", 42);

    Ok(())
}

License

This project is licensed under the MIT License.

No runtime deps