use clap::{crate_version, App, Arg};
use log::*;
use std::str::FromStr;
fn main() {
let m = App::new("buche example")
.version(crate_version!())
.arg(
Arg::with_name("verbosity")
.short('v')
.multiple(true)
.help("Increase message verbosity"),
)
.arg(
Arg::with_name("quiet")
.short('q')
.help("Silence all output"),
)
.arg(
Arg::with_name("timestamp")
.short('t')
.help("prepend log lines with a timestamp")
.takes_value(true)
.possible_values(&["none", "sec", "ms", "us", "ns"]),
)
.get_matches();
let verbose = m.occurrences_of("verbosity") as usize;
let quiet = m.is_present("quiet");
let ts = m
.value_of("timestamp")
.map(|v| {
buche::Timestamp::from_str(v).unwrap_or_else(|_| {
clap::Error::raw(
clap::ErrorKind::InvalidValue,
"invalid value for 'timestamp'",
)
.exit()
})
})
.unwrap_or(buche::Timestamp::Off);
buche::new()
.module(module_path!())
.quiet(quiet)
.verbosity(verbose)
.timestamp(ts)
.init()
.unwrap();
trace!("trace message");
debug!("debug message");
info!("info message");
warn!("warn message");
error!("error message");
}