log: write to stderr when using init_cli_logger, export tracing::Level

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@proxmox.com>
Reviewed-by: Christian Ebner <c.ebner@proxmox.com>
Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
This commit is contained in:
Gabriel Goller 2024-09-04 15:28:56 +02:00 committed by Wolfgang Bumiller
parent a46dd1a60a
commit 5933c2f47b

View File

@ -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
}))