Commit 5f6256a4 authored by Alexandre Pere's avatar Alexandre Pere

Adds more logging possibilities

parent 548d11b6
......@@ -28,7 +28,9 @@ impl Visit for EchoVisitor{
// This logger only echoes messages to stderr, without any more formatting.
pub enum EchoSubscriber{
Normal,
Verbose
Verbose,
Ssh,
Trace(String)
}
impl EchoSubscriber{
......@@ -40,13 +42,28 @@ impl EchoSubscriber{
tracing::subscriber::set_global_default(EchoSubscriber::Verbose)
.expect("Setting logger failed.");
}
pub fn setup_ssh(){
tracing::subscriber::set_global_default(EchoSubscriber::Ssh)
.expect("Setting logger failed.");
}
pub fn setup_trace(module: String){
tracing::subscriber::set_global_default(EchoSubscriber::Trace(module))
.expect("Setting logger failed.");
}
}
impl Subscriber for EchoSubscriber{
fn enabled(&self, metadata: &Metadata) -> bool {
match (self, metadata.level()){
(_, &Level::INFO) | (_, &Level::ERROR) => true,
(EchoSubscriber::Verbose, &Level::DEBUG) | (EchoSubscriber::Verbose, &Level::WARN) => true,
match (self, metadata.level(), metadata.target()){
(_, &Level::INFO, _) => true,
(_, &Level::ERROR, _) => true,
(EchoSubscriber::Verbose, &Level::DEBUG, t) if t != "liborchestra::ssh" => true,
(EchoSubscriber::Verbose, &Level::WARN, _) => true,
(EchoSubscriber::Ssh, &Level::DEBUG, "liborchestra::ssh") => true,
(EchoSubscriber::Ssh, &Level::WARN, "liborchestra::ssh") => true,
(EchoSubscriber::Trace(m), &Level::TRACE, t) if t == format!("liborchestra::{}", m) => true,
(EchoSubscriber::Trace(_), &Level::DEBUG, _) => true,
_ => false
}
}
......
......@@ -69,6 +69,13 @@ fn main(){
.short("V")
.long("verbose")
.help("Print more messages"))
.arg(clap::Arg::with_name("debug-ssh")
.long("debug-ssh")
.help("Print ssh messages"))
.arg(clap::Arg::with_name("trace")
.takes_value(true)
.long("trace")
.help("Print trace message of the mentionned module"))
.arg(clap::Arg::with_name("silent")
.short("S")
.long("silent")
......@@ -130,6 +137,13 @@ fn main(){
.short("V")
.long("verbose")
.help("Print more messages"))
.arg(clap::Arg::with_name("debug-ssh")
.long("debug-ssh")
.help("Print ssh messages"))
.arg(clap::Arg::with_name("trace")
.takes_value(true)
.long("trace")
.help("Print trace message of the mentionned module"))
.arg(clap::Arg::with_name("silent")
.short("S")
.long("silent")
......@@ -230,6 +244,13 @@ fn main(){
.short("V")
.long("verbose")
.help("Print more messages"))
.arg(clap::Arg::with_name("debug-ssh")
.long("debug-ssh")
.help("Print ssh messages"))
.arg(clap::Arg::with_name("trace")
.takes_value(true)
.long("trace")
.help("Print trace message of the mentionned module"))
.arg(clap::Arg::with_name("silent")
.short("S")
.long("silent")
......
......@@ -285,6 +285,10 @@ pub fn init_logger(matches: &clap::ArgMatches) {
if matches.is_present("silent"){
} else if matches.is_present("verbose"){
EchoSubscriber::setup_verbose();
} else if matches.is_present("debug-ssh"){
EchoSubscriber::setup_ssh();
} else if matches.is_present("trace"){
EchoSubscriber::setup_trace(matches.value_of("trace").unwrap().to_owned());
} else {
EchoSubscriber::setup_normal();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment