From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id B44DE9B235 for ; Wed, 24 May 2023 15:58:06 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 912E81F66E for ; Wed, 24 May 2023 15:57:36 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 24 May 2023 15:57:33 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D1A2546E4D for ; Wed, 24 May 2023 15:57:31 +0200 (CEST) From: Lukas Wagner To: pve-devel@lists.proxmox.com Date: Wed, 24 May 2023 15:56:25 +0200 Message-Id: <20230524135649.934881-19-l.wagner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230524135649.934881-1-l.wagner@proxmox.com> References: <20230524135649.934881-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.167 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH v2 proxmox-perl-rs 18/42] log: set default log level to 'info', add product specific logging env var X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 May 2023 13:58:06 -0000 Logging behaviour can be overridden by the {PMG,PVE}_LOG environment variable. This commit also disables styled output and timestamps in log messages, since we usually log to the journal anyway. The log output is configured to match with other log messages in task logs. Signed-off-by: Lukas Wagner --- common/src/logger.rs | 12 ++++++++++-- pmg-rs/src/lib.rs | 2 +- pve-rs/src/lib.rs | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/common/src/logger.rs b/common/src/logger.rs index 36dc856..3c9a075 100644 --- a/common/src/logger.rs +++ b/common/src/logger.rs @@ -1,6 +1,14 @@ +use env_logger::{Builder, Env}; +use std::io::Write; + /// Initialize logging. Should only be called once -pub fn init() { - if let Err(e) = env_logger::try_init() { +pub fn init(env_var_name: &str, default_log_level: &str) { + if let Err(e) = Builder::from_env(Env::new().filter_or(env_var_name, default_log_level)) + .format(|buf, record| writeln!(buf, "{}: {}", record.level(), record.args())) + .write_style(env_logger::WriteStyle::Never) + .format_timestamp(None) + .try_init() + { eprintln!("could not set up env_logger: {e}"); } } diff --git a/pmg-rs/src/lib.rs b/pmg-rs/src/lib.rs index 8633136..6b7ee4c 100644 --- a/pmg-rs/src/lib.rs +++ b/pmg-rs/src/lib.rs @@ -12,6 +12,6 @@ mod export { #[export] pub fn init() { - common::logger::init(); + common::logger::init("PMG_LOG", "info"); } } diff --git a/pve-rs/src/lib.rs b/pve-rs/src/lib.rs index fc31b3a..eb6ae02 100644 --- a/pve-rs/src/lib.rs +++ b/pve-rs/src/lib.rs @@ -14,6 +14,6 @@ mod export { #[export] pub fn init() { - common::logger::init(); + common::logger::init("PVE_LOG", "info"); } } -- 2.30.2