From: Thomas Ellmenreich <t.ellmenreich@proxmox.com>
To: pdm-devel@lists.proxmox.com
Cc: Thomas Ellmenreich <t.ellmenreich@proxmox.com>
Subject: [PATCH proxmox v2 1/7] log: replace per layer filtering with one global filter
Date: Fri, 23 Oct 2026 13:31:12 +0200 [thread overview]
Message-ID: <20261023113120.332453-2-t.ellmenreich@proxmox.com> (raw)
In-Reply-To: <20261023113120.332453-1-t.ellmenreich@proxmox.com>
Instead of filtering with the global filter on every layer, provide one
global filter once, as described in [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 <t.ellmenreich@proxmox.com>
---
proxmox-log/src/builder.rs | 40 +++++++++++++-------------------------
1 file changed, 13 insertions(+), 27 deletions(-)
diff --git a/proxmox-log/src/builder.rs b/proxmox-log/src/builder.rs
index 6fcf1cc9..bbac7797 100644
--- a/proxmox-log/src/builder.rs
+++ b/proxmox-log/src/builder.rs
@@ -1,7 +1,8 @@
use tracing::Level;
use tracing::Metadata;
use tracing::level_filters::LevelFilter;
-use tracing_log::{AsLog, LogTracer};
+use tracing_log::AsLog;
+use tracing_log::LogTracer;
use tracing_subscriber::Layer;
use tracing_subscriber::layer::Context;
use tracing_subscriber::layer::Filter;
@@ -76,11 +77,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 +87,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 +96,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 +104,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 +114,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
}
@@ -143,7 +127,6 @@ impl Logger {
let layer = tracing_subscriber::fmt::layer()
.event_format(PveTaskFormatter {})
.with_writer(std::io::stderr)
- .with_filter(self.global_log_level)
.boxed();
self.layer.push(layer);
self
@@ -153,7 +136,10 @@ 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())?;
--
2.47.3
next prev parent reply other threads:[~2026-10-23 11:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 11:31 [PATCH datacenter-manager/proxmox v2 0/7] log: allow finegrained control log levels Thomas Ellmenreich
2026-10-23 11:31 ` Thomas Ellmenreich [this message]
2026-10-23 11:31 ` [PATCH proxmox v2 2/7] fix #6081: log: replace simple level filter with env filter Thomas Ellmenreich
2026-10-23 11:31 ` [PATCH proxmox v2 3/7] log: add tests to the logger Thomas Ellmenreich
2026-10-23 11:31 ` [PATCH proxmox v2 4/7] log: clean up of logger components Thomas Ellmenreich
2026-10-23 11:31 ` [PATCH proxmox v2 5/7] rest-server: enable debug based on log level Thomas Ellmenreich
2026-10-23 11:31 ` [PATCH datacenter-manager v2 6/7] api: remove manual setting of REST server debug flag Thomas Ellmenreich
2026-10-23 11:31 ` [PATCH datacenter-manager v2 7/7] api: rename PROXMOX_DEBUG log variable to PDM_LOG Thomas Ellmenreich
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=20261023113120.332453-2-t.ellmenreich@proxmox.com \
--to=t.ellmenreich@proxmox.com \
--cc=pdm-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.