#cli

vlog

Macros to do stdout / stderr logs based on verbosity level

5 releases

Uses old Rust 2015

0.1.4 May 9, 2018
0.1.3 May 8, 2018
0.1.2 Apr 24, 2018
0.1.1 Apr 14, 2018
0.1.0 Apr 14, 2018

#615 in Command-line interface

Download history 10969/week @ 2024-07-29 15458/week @ 2024-08-05 220/week @ 2024-08-12 89/week @ 2024-08-19 270/week @ 2024-08-26 95/week @ 2024-09-02 286/week @ 2024-09-09 190/week @ 2024-09-16 309/week @ 2024-09-23 169/week @ 2024-09-30 205/week @ 2024-10-07 136/week @ 2024-10-14 376/week @ 2024-10-21 209/week @ 2024-10-28 50/week @ 2024-11-04 77/week @ 2024-11-11

718 downloads per month
Used in 4 crates

MIT license

10KB
94 lines

vlog-rs

Build Status Build status codecov Crates.io Docs.rs License: MIT

Macros to do stdout / stderr logs based on verbosity level, which take in the same arguments as println! macro.

Useful for CLI applications. The default verbosity level is 0, and the supported max verbosity level is 3, which is equivalent to -vvv flags as seen in most Linux CLI applications.

Example

#[macro_use]
extern crate vlog;

use vlog::{get_verbosity_level, set_verbosity_level};

fn main() {
    // default verbosity level is 0
    assert_eq!(0, get_verbosity_level());

    v0!("v0 stdout prints");
    v1!("v1 stdout won't print");
    v2!("v2 stdout won't print");
    v3!("v3 stdout won't print");

    // set custom verbosity level
    set_verbosity_level(1);
    assert_eq!(1, get_verbosity_level());

    v0!("{} stdout prints", "v0");
    v1!("{} stdout prints", "v1");
    v2!("{} stdout won't print", "v2");
    v3!("{} stdout won't print", "v3");

    // set custom max verbosity level
    set_verbosity_level(3);
    assert_eq!(3, get_verbosity_level());

    v0!("{} stdout prints", "v0");
    v1!("{} stdout prints", "v1");
    v2!("{} stdout prints", "v2");
    v3!("{} stdout prints", "v3");

    // stderr macros also available
    ve0!("{} stderr prints", "ve0");
    ve1!("{} stderr prints", "ve1");
    ve2!("{} stderr prints", "ve2");
    ve3!("{} stderr prints", "ve3");
}

No runtime deps