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) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id F2B699A472 for ; Fri, 13 Oct 2023 14:36:54 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D26DF1E312 for ; Fri, 13 Oct 2023 14:36:24 +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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 13 Oct 2023 14:36:23 +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 7FBDA48F12 for ; Fri, 13 Oct 2023 14:36:23 +0200 (CEST) Content-Type: multipart/alternative; boundary="------------yahbtRR0kTr310uez2wQ2cq5" Message-ID: Date: Fri, 13 Oct 2023 14:36:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Gabriel Goller To: pbs-devel@lists.proxmox.com Reply-To: Proxmox Backup Server development discussion References: <20231011140102.273423-1-g.goller@proxmox.com> <20231011140102.273423-3-g.goller@proxmox.com> Content-Language: en-US In-Reply-To: <20231011140102.273423-3-g.goller@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL -0.337 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 HTML_MESSAGE 0.001 HTML included in message 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lib.rs] Subject: Re: [pbs-devel] [RFC proxmox 2/2] proxmox-log: added tracing infra X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Oct 2023 12:36:55 -0000 This is a multi-part message in MIME format. --------------yahbtRR0kTr310uez2wQ2cq5 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Some things that are gonna get fixed with v2: On 10/11/23 16:01, Gabriel Goller wrote: > [..] > + > +tokio::task_local! { > + pub static LOGGER: RefCell>; > + pub static WARN_COUNTER: RefCell>; > +} Move the `task_local!` stuff to the lib.rs file, that is probably cleaner... > [..] > + > +pub fn init_logger( > + env_var_name: &str, > + default_log_level: LevelFilter, > + application_name: &str, > +) -> Result<(), anyhow::Error> { > + let mut log_level = default_log_level; > + if let Ok(v) = env::var(env_var_name) { > + if let Ok(l) = v.parse::() { > + log_level = l; > + } > + } > + let registry = tracing_subscriber::registry() > + .with(FilelogLayer::new().with_filter(filter_fn(|metadata| { > + metadata.fields().field("tasklog").is_some() > + }))) > + .with(SyslogLayer::new(application_name.to_string()).with_filter(log_level)); > + We also need the `.with_filter(log_level)` on the `FilelogLayer`, so that the PBS_LOG variable also sets the log level on the task logs. > + tracing::subscriber::set_global_default(registry)?; > + > + LogTracer::init()?; Use `init_with_filter` here, so that we also set the loglevel on the (underlying) `log` implementation. Like that a `log::info` call for example doesn't even forward the message to `tracing`. > + Ok(()) > +} > [..] --------------yahbtRR0kTr310uez2wQ2cq5 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

Some things that are gonna get fixed with v2:

On 10/11/23 16:01, Gabriel Goller wrote:
[..]
+
+tokio::task_local! {
+    pub static LOGGER: RefCell<Option<FileLogger>>;
+    pub static WARN_COUNTER: RefCell<Option<u64>>;
+}
Move the `task_local!` stuff to the lib.rs file, that is
probably cleaner...
[..]
+
+pub fn init_logger(
+    env_var_name: &str,
+    default_log_level: LevelFilter,
+    application_name: &str,
+) -> Result<(), anyhow::Error> {
+    let mut log_level = default_log_level;
+    if let Ok(v) = env::var(env_var_name) {
+        if let Ok(l) = v.parse::<LevelFilter>() {
+            log_level = l;
+        }
+    }
+    let registry = tracing_subscriber::registry()
+        .with(FilelogLayer::new().with_filter(filter_fn(|metadata| {
+            metadata.fields().field("tasklog").is_some()
+        })))
+        .with(SyslogLayer::new(application_name.to_string()).with_filter(log_level));
+
We also need the `.with_filter(log_level)` on the `FilelogLayer`, so
that the PBS_LOG variable also sets the log level on the task logs.
+    tracing::subscriber::set_global_default(registry)?;
+
+    LogTracer::init()?;

Use `init_with_filter` here, so that we also set the loglevel on the (underlying) `log`
implementation. Like that a `log::info` call for example doesn't even
forward the message to `tracing`.

+    Ok(())
+}
[..]
--------------yahbtRR0kTr310uez2wQ2cq5--