Logger that logs to stderr based on verbosity specified
Module documentation with examples
Add this to your Cargo.toml
:
toml
[dependencies]
stderrlog = "*"
and this to your crate root:
rust
extern crate stderrlog;
and this to your main():
rust
stderrlog::new().verbosity(args.flag_v).quiet(args.flag_q).init().unwrap();
where your getopt/Docopt args are defined as:
rust
struct {
flag_v: usize,
flag_q: bool,
...
}
```rust extern crate docopt;
extern crate log; extern crate rustc_serialize; extern crate stderrlog;
use docopt::Docopt;
const USAGE: &'static str = " Usage: program [-q] [-v...] ";
struct Args { flagq: bool, flagv: usize, }
fn main() { let args: Args = Docopt::new(USAGE) .andthen(|d| d.decode()) .unwrapor_else(|e| e.exit());
stderrlog::new()
.module(module_path!())
.quiet(args.flag_q)
.verbosity(args.flag_v)
.init()
.unwrap();
info!("starting up");
// ...
}