Crate vlog [] [src]

vlog

Macros to do stdout / stderr logs based on verbosity level.

Useful for CLI applications. The default verbosity level is 0, and the supported max verbosity level is 3, which is equivalent to -vvv flags 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");
}

Macros

v0

Always prints to stdout. Follows format! style.

v1

Prints to stdout if verbosity level is >= 1. Follows format! style.

v2

Prints to stdout if verbosity level is >= 2. Follows format! style.

v3

Prints to stdout if verbosity level is >= 3. Follows format! style.

ve0

Always prints to stderr. Follows format! style.

ve1

Prints to stderr if verbosity level is >= 1. Follows format! style.

ve2

Prints to stderr if verbosity level is >= 2. Follows format! style.

ve3

Prints to stderr if verbosity level is >= 3. Follows format! style.

verbose_elog

Common macro for verbose stderr logs. This is meant to be used internally only.

verbose_log

Common macro for verbose stdout logs. This is meant to be used internally only.

Functions

get_verbosity_level

Gets the application verbosity level atomically. This method is thread-safe.

set_verbosity_level

Sets the application verbosity level atomically. This method is thread-safe.