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

@@ -1,6 +1,10 @@
port = 1965 port = 1965
# use "::" for ipv6 and ipv4 or "0.0.0.0" for ipv4 only # use "::" for ipv6 and ipv4 or "0.0.0.0" for ipv4 only
host = "::" host = "::"
# log is optional and server wide. It defaults to info if not set. Other levels
# are error, warn, and info. If error is set it will only show error. If warn
# is set it will show error and warn. Info shows all three.
log = "info"
# There must be at least 1 server tag if a client doesn't send sni the server # There must be at least 1 server tag if a client doesn't send sni the server
# will use this tag as its default. # will use this tag as its default.

View File

@@ -8,6 +8,7 @@ use toml::de::Error;
pub struct Config { pub struct Config {
pub port: u16, pub port: u16,
pub host: String, pub host: String,
pub log: Option<String>,
pub server: Vec<Server>, pub server: Vec<Server>,
} }

View File

@@ -300,7 +300,6 @@ async fn handle_connection(
} }
fn main() -> io::Result<()> { fn main() -> io::Result<()> {
simple_logger::init_with_level(log::Level::Info).unwrap();
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
if args.len() != 2 { if args.len() != 2 {
println!("Please run with the path to the config file."); println!("Please run with the path to the config file.");
@@ -319,6 +318,21 @@ fn main() -> io::Result<()> {
return Ok(()); 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 cmap = cfg.to_map();
let default = &cfg.server[0].hostname; let default = &cfg.server[0].hostname;
println!("Serving {} vhosts", cfg.server.len()); println!("Serving {} vhosts", cfg.server.len());