[pbs-devel] [PATCH proxmox 1/10] router: add init_cli_logger helper function

Hannes Laimer h.laimer at proxmox.com
Fri Mar 11 16:07:46 CET 2022


Signed-off-by: Hannes Laimer <h.laimer at proxmox.com>
---
 proxmox-router/Cargo.toml     |  1 +
 proxmox-router/src/cli/mod.rs | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/proxmox-router/Cargo.toml b/proxmox-router/Cargo.toml
index d9f47ea..29c717c 100644
--- a/proxmox-router/Cargo.toml
+++ b/proxmox-router/Cargo.toml
@@ -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.19.1"
diff --git a/proxmox-router/src/cli/mod.rs b/proxmox-router/src/cli/mod.rs
index cc72402..41944dc 100644
--- a/proxmox-router/src/cli/mod.rs
+++ b/proxmox-router/src/cli/mod.rs
@@ -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.
-- 
2.30.2






More information about the pbs-devel mailing list