Crate loggerv [] [src]

A simple io::stdout and io::stderr writing Logger implementation from the log crate, using the ansi_term crate for colors and configured at runtime, or at compile time with simple function calls. Designed for simple CLIs.

This library only comes with 3 public ways to initialize the global logger. Ensure you call one of these exactly once early in your rust program as shown in one of the examples below.

Example

The standard example with clap as the arg parser.

#[macro_use] extern crate log;
extern crate clap;
extern crate loggerv;

use clap::{Arg, App};

fn main() {
    let args = App::new("app")
                   .arg(Arg::with_name("v")
                            .short("v")
                            .multiple(true)
                            .help("Sets the level of verbosity"))
                   .get_matches();

    loggerv::init_with_verbosity(args.occurrences_of("v")).unwrap();

    error!("this is always printed");
    warn!("this too, and it's printed to stderr");
    info!("this is optional");  // for ./app -v or higher
    debug!("this is optional"); // for ./app -vv or higher
    trace!("this is optional"); // for ./app -vvv
}

But obviously use whatever argument parsing methods you prefer.

Example

For a compile time switch, all you really need is log (for the macros) and loggerv for how to print what's being sent to the macros.

#[macro_use] extern crate log;
extern crate loggerv;

use log::LogLevel;

fn main() {
    loggerv::init_with_level(LogLevel::Info).unwrap();
    debug!("this is a debug {}", "message");
    error!("this is printed by default");
}

Example

If you don't really care at all you could just use the plain init_quiet function to only show warnings and errors:

#[macro_use] extern crate log;
extern crate loggerv;

fn main() {
    loggerv::init_quiet().unwrap();
    info!("hidden");
    error!("this is printed by default");
}

See the documentation for the log crate for more information about its API.

Functions

init_quiet

Initializes loggerv with only warnings and errors.

init_with_level

Initialize loggerv with a maximal log level.

init_with_verbosity

Initialize loggerv with a verbosity level.