[pbs-devel] [PATCH v2] log: write to stderr when using init_cli_logger, export tracing::Level

Gabriel Goller g.goller at proxmox.com
Wed Sep 4 15:28:56 CEST 2024


Previously when using `env_logger` all of our cli-tools logged to
stderr, make tracing do the same. Export `tracing::Level` so that we can
use the `tracing::enabled!` macro.

Tested-by: Christian Ebner <c.ebner at proxmox.com>
Reviewed-by: Christian Ebner <c.ebner at proxmox.com>
Signed-off-by: Gabriel Goller <g.goller at proxmox.com>
---

v2: nothing changed

 proxmox-log/src/lib.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/proxmox-log/src/lib.rs b/proxmox-log/src/lib.rs
index bcde5495dead..0cf5cb7a50b2 100644
--- a/proxmox-log/src/lib.rs
+++ b/proxmox-log/src/lib.rs
@@ -6,7 +6,6 @@ use std::future::Future;
 use std::sync::{Arc, Mutex};
 
 use tokio::task::futures::TaskLocalFuture;
-use tracing::Level;
 use tracing_log::{AsLog, LogTracer};
 use tracing_subscriber::filter::filter_fn;
 use tracing_subscriber::prelude::*;
@@ -32,6 +31,7 @@ pub use tracing::trace;
 pub use tracing::trace_span;
 pub use tracing::warn;
 pub use tracing::warn_span;
+pub use tracing::Level;
 pub use tracing_subscriber::filter::LevelFilter;
 
 tokio::task_local! {
@@ -154,6 +154,7 @@ pub fn init_cli_logger(
         .with(
             tracing_subscriber::fmt::layer()
                 .event_format(format)
+                .with_writer(std::io::stderr)
                 .with_filter(filter_fn(|metadata| {
                     !LogContext::exists() || *metadata.level() >= Level::ERROR
                 }))
-- 
2.39.2





More information about the pbs-devel mailing list