Added log levels

This commit is contained in:
int 80h
2020-05-28 17:56:42 -04:00
parent 44f37e139b
commit 258d2b9ef6
3 changed files with 20 additions and 1 deletions

View File

@@ -300,7 +300,6 @@ async fn handle_connection(
}
fn main() -> io::Result<()> {
simple_logger::init_with_level(log::Level::Info).unwrap();
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
println!("Please run with the path to the config file.");
@@ -319,6 +318,21 @@ fn main() -> io::Result<()> {
return Ok(());
},
};
let loglev = match &cfg.log {
None => log::Level::Info,
Some(l) => {
match l.as_str() {
"error" => log::Level::Error,
"warn" => log::Level::Warn,
"info" => log::Level::Info,
_ => {
eprintln!("Incorrect log level in config file.");
return Ok(());
},
}
},
};
simple_logger::init_with_level(loglev).unwrap();
let cmap = cfg.to_map();
let default = &cfg.server[0].hostname;
println!("Serving {} vhosts", cfg.server.len());