From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 62E791FF09C for ; Mon, 21 Sep 2026 11:53:19 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id F056221480; Mon, 21 Sep 2026 11:53:18 +0200 (CEST) From: Thomas Ellmenreich To: pdm-devel@lists.proxmox.com Subject: [PATCH proxmox 1/5] log: replace per layer filtering by one global filter Date: Mon, 21 Sep 2026 11:51:54 +0200 Message-ID: <20260921095210.229315-3-t.ellmenreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260921095210.229315-2-t.ellmenreich@proxmox.com> References: <20260921095210.229315-2-t.ellmenreich@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1789984393263 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.602 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) KAM_SHORT 0.001 Use of a URL Shortener for very short URL RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: XAENO4TX7HOTH57UYTYEAHBRCPEZZN6Z X-Message-ID-Hash: XAENO4TX7HOTH57UYTYEAHBRCPEZZN6Z X-MailFrom: t.ellmenreich@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Thomas Ellmenreich X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Instead of filtering with the global filter on every layer, provide one global filter once, as described here: [0] This is also in preparation for filters that either have to be cloned or cannot be cloned at all, like EnvFilters* [1]. * EnvFilter can be cloned from tracing_subscriber version 0.3.20 onwards. [0]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/layer/index.html#global-filtering [1]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html Signed-off-by: Thomas Ellmenreich --- proxmox-log/src/builder.rs | 48 +++++++++------------------ proxmox-log/src/pve_task_formatter.rs | 2 +- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/proxmox-log/src/builder.rs b/proxmox-log/src/builder.rs index 6fcf1cc9..3108ea29 100644 --- a/proxmox-log/src/builder.rs +++ b/proxmox-log/src/builder.rs @@ -1,8 +1,9 @@ use tracing::Level; use tracing::Metadata; use tracing::level_filters::LevelFilter; -use tracing_log::{AsLog, LogTracer}; +use tracing_log::LogTracer; use tracing_subscriber::Layer; +use tracing_subscriber::Registry; use tracing_subscriber::layer::Context; use tracing_subscriber::layer::Filter; use tracing_subscriber::layer::SubscriberExt; @@ -55,9 +56,7 @@ impl Filter for NoWorkerTask { /// ``` pub struct Logger { global_log_level: LevelFilter, - layer: Vec< - Box + Send + Sync + 'static>, - >, + layer: Vec + Send + Sync + 'static>>, } impl Logger { @@ -76,11 +75,7 @@ impl Logger { /// /// If the journal cannot be opened, print to stderr instead. pub fn journald(mut self) -> Logger { - self.layer.push( - journald_or_stderr_layer() - .with_filter(self.global_log_level) - .boxed(), - ); + self.layer.push(journald_or_stderr_layer().boxed()); self } @@ -90,12 +85,8 @@ impl Logger { /// no LogContext exists – which means we are not in a PBS workertask – or the level of the /// log message is 'ERROR'. pub fn journald_on_no_workertask(mut self) -> Logger { - self.layer.push( - journald_or_stderr_layer() - .with_filter(NoWorkerTask) - .with_filter(self.global_log_level) - .boxed(), - ); + self.layer + .push(journald_or_stderr_layer().with_filter(NoWorkerTask).boxed()); self } @@ -103,8 +94,7 @@ impl Logger { /// /// Check if a LogContext exists and if it does, print to the corresponding task log file. pub fn tasklog_pbs(mut self) -> Logger { - self.layer - .push(TasklogLayer {}.with_filter(self.global_log_level).boxed()); + self.layer.push(TasklogLayer.boxed()); self } @@ -112,11 +102,7 @@ impl Logger { /// /// Prints all the events to stderr with the compact format (no level, no timestamp). pub fn stderr(mut self) -> Logger { - self.layer.push( - plain_stderr_layer() - .with_filter(self.global_log_level) - .boxed(), - ); + self.layer.push(plain_stderr_layer().boxed()); self } @@ -126,12 +112,8 @@ impl Logger { /// triggered if no workertask could be found (no LogContext exists) or the event level is /// `ERROR`. pub fn stderr_on_no_workertask(mut self) -> Logger { - self.layer.push( - plain_stderr_layer() - .with_filter(NoWorkerTask) - .with_filter(self.global_log_level) - .boxed(), - ); + self.layer + .push(plain_stderr_layer().with_filter(NoWorkerTask).boxed()); self } @@ -141,9 +123,8 @@ impl Logger { /// e.g.: `DEBUG: event message`. pub fn stderr_pve(mut self) -> Logger { let layer = tracing_subscriber::fmt::layer() - .event_format(PveTaskFormatter {}) + .event_format(PveTaskFormatter) .with_writer(std::io::stderr) - .with_filter(self.global_log_level) .boxed(); self.layer.push(layer); self @@ -153,10 +134,13 @@ impl Logger { /// /// Also configures the `LogTracer` which will convert all `log` events to tracing events. pub fn init(self) -> Result<(), anyhow::Error> { - let registry = tracing_subscriber::registry().with(self.layer); + let registry = tracing_subscriber::registry() + .with(self.layer) + .with(self.global_log_level); + tracing::subscriber::set_global_default(registry)?; - LogTracer::init_with_filter(self.global_log_level.as_log())?; + LogTracer::init()?; Ok(()) } } diff --git a/proxmox-log/src/pve_task_formatter.rs b/proxmox-log/src/pve_task_formatter.rs index e9866a4b..12bc33c8 100644 --- a/proxmox-log/src/pve_task_formatter.rs +++ b/proxmox-log/src/pve_task_formatter.rs @@ -8,7 +8,7 @@ use tracing_subscriber::registry::LookupSpan; /// This custom formatter outputs logs as they are visible in the PVE task log. /// /// e.g.: "DEBUG: sample message" -pub struct PveTaskFormatter {} +pub struct PveTaskFormatter; impl FormatEvent for PveTaskFormatter where -- 2.47.3