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 44F4791C3E for ; Mon, 27 Mar 2023 17:19:53 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1ABBFD4CA for ; Mon, 27 Mar 2023 17:19:23 +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 ; Mon, 27 Mar 2023 17:19:22 +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 070FD46FD3 for ; Mon, 27 Mar 2023 17:19:22 +0200 (CEST) From: Lukas Wagner To: pve-devel@lists.proxmox.com Date: Mon, 27 Mar 2023 17:18:46 +0200 Message-Id: <20230327151857.495565-8-l.wagner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230327151857.495565-1-l.wagner@proxmox.com> References: <20230327151857.495565-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.433 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 KAM_NUMSUBJECT 0.5 Subject ends in numbers excluding current years SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH proxmox-perl-rs 07/18] log: set default log level to 'info', add product specfig logging env var1 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: Mon, 27 Mar 2023 15:19:53 -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 5914bc9..d5c1080 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 671aad0..af3076e 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