public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 1/10] router: add init_cli_logger helper function
Date: Fri, 11 Mar 2022 15:07:46 +0000	[thread overview]
Message-ID: <20220311150755.73338-2-h.laimer@proxmox.com> (raw)
In-Reply-To: <20220311150755.73338-1-h.laimer@proxmox.com>

Signed-off-by: Hannes Laimer <h.laimer@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





  reply	other threads:[~2022-03-11 15:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-11 15:07 [pbs-devel] [PATCH-SERIES] replace print by log macro in libraries Hannes Laimer
2022-03-11 15:07 ` Hannes Laimer [this message]
2022-03-11 15:07 ` [pbs-devel] [PATCH proxmox-backup 02/10] bins: init cli logger Hannes Laimer
2022-03-11 15:07 ` [pbs-devel] [PATCH proxmox-backup 03/10] pbs-client: replace print with log macro Hannes Laimer
2022-03-11 15:07 ` [pbs-devel] [PATCH proxmox-backup 04/10] pbs-datastore: " Hannes Laimer
2022-03-11 15:07 ` [pbs-devel] [PATCH proxmox-backup 05/10] pbs-fuse+pbs-tape: " Hannes Laimer
2022-03-11 15:07 ` [pbs-devel] [PATCH proxmox-backup 06/10] proxmox-backup-client: " Hannes Laimer
2022-03-11 15:07 ` [pbs-devel] [PATCH proxmox-backup 07/10] proxmox-file-restore: " Hannes Laimer
2022-03-11 15:07 ` [pbs-devel] [PATCH proxmox-backup 08/10] proxmox-rest-server: " Hannes Laimer
2022-03-11 15:07 ` [pbs-devel] [PATCH proxmox-backup 09/10] " Hannes Laimer
2022-03-11 15:07 ` [pbs-devel] [PATCH proxmox-backup 10/10] docs: add note for setting verbosity level Hannes Laimer
2022-03-17  8:40 ` [pbs-devel] [PATCH-SERIES] replace print by log macro in libraries Wolfgang Bumiller
2022-03-18  6:02   ` Hannes Laimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220311150755.73338-2-h.laimer@proxmox.com \
    --to=h.laimer@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal