Skip to content

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

License

Notifications You must be signed in to change notification settings

veeso/verbose-macros

Repository files navigation

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.

About

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

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages