mirror of
https://framagit.org/veretcle/scootaloo.git
synced 2025-07-20 17:11:19 +02:00
Adding logging facility
This commit is contained in:
25
src/main.rs
25
src/main.rs
@@ -4,6 +4,13 @@ use scootaloo::*;
|
|||||||
// clap
|
// clap
|
||||||
use clap::{App, Arg, SubCommand};
|
use clap::{App, Arg, SubCommand};
|
||||||
|
|
||||||
|
// log
|
||||||
|
use log::{LevelFilter, error};
|
||||||
|
use simple_logger::SimpleLogger;
|
||||||
|
|
||||||
|
// std
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let matches = App::new(env!("CARGO_PKG_NAME"))
|
let matches = App::new(env!("CARGO_PKG_NAME"))
|
||||||
.version(env!("CARGO_PKG_VERSION"))
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
@@ -15,6 +22,13 @@ fn main() {
|
|||||||
.help("TOML config file for scootaloo (default /usr/local/etc/scootaloo.toml)")
|
.help("TOML config file for scootaloo (default /usr/local/etc/scootaloo.toml)")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.display_order(1))
|
.display_order(1))
|
||||||
|
.arg(Arg::with_name("log_level")
|
||||||
|
.short("l")
|
||||||
|
.long("loglevel")
|
||||||
|
.value_name("LOGLEVEL")
|
||||||
|
.help("Log level. Valid values are: Off, Warn, Error, Info, Debug")
|
||||||
|
.takes_value(true)
|
||||||
|
.display_order(2))
|
||||||
.subcommand(SubCommand::with_name("register")
|
.subcommand(SubCommand::with_name("register")
|
||||||
.version(env!("CARGO_PKG_VERSION"))
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
.about("Command to register to a Mastodon Instance")
|
.about("Command to register to a Mastodon Instance")
|
||||||
@@ -32,7 +46,18 @@ fn main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if matches.is_present("log_level") {
|
||||||
|
match LevelFilter::from_str(matches.value_of("log_level").unwrap()) {
|
||||||
|
Ok(level) => { SimpleLogger::new().with_level(level).init().unwrap()},
|
||||||
|
Err(e) => {
|
||||||
|
SimpleLogger::new().with_level(LevelFilter::Error).init().unwrap();
|
||||||
|
error!("Unknown log level filter: {}", e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let config = parse_toml(matches.value_of("config").unwrap_or("/usr/local/etc/scootaloo.toml"));
|
let config = parse_toml(matches.value_of("config").unwrap_or("/usr/local/etc/scootaloo.toml"));
|
||||||
|
|
||||||
run(config);
|
run(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user