router: add init_cli_logger helper function

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Hannes Laimer 2022-06-15 08:19:47 +00:00 committed by Wolfgang Bumiller
parent 41d8747de3
commit 32b8ae982f
2 changed files with 12 additions and 0 deletions

View File

@ -10,6 +10,7 @@ exclude = [ "debian" ]
[dependencies]
anyhow = "1.0"
env_logger = "0.9"
http = "0.2"
hyper = { version = "0.14", features = [ "full" ] }
nix = "0.24.1"

View File

@ -49,6 +49,17 @@ pub use readline::*;
/// return a list of all possible values.
pub type CompletionFunction = fn(&str, &HashMap<String, String>) -> Vec<String>;
/// Initialize default logger for CLI binaries
pub fn init_cli_logger(env_var_name: &str, default_log_level: &str) {
env_logger::Builder::from_env(env_logger::Env::new().filter_or(env_var_name, default_log_level))
.write_style(env_logger::WriteStyle::Never)
.format_level(false)
.format_module_path(false)
.format_target(false)
.format_timestamp(None)
.init();
}
/// Define a simple CLI command.
pub struct CliCommand {
/// The Schema definition.