From 1a29be99cd4521b83a343f2ebe946a5d1b505db8 Mon Sep 17 00:00:00 2001 From: tyranron Date: Mon, 20 Jan 2025 17:28:04 +0200 Subject: [PATCH] Try new API --- src/tracing.rs | 34 ++++++++++++++++++---------------- tests/json.rs | 10 +++++++--- tests/junit.rs | 10 +++++++--- tests/tracing.rs | 10 +++++++--- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/tracing.rs b/src/tracing.rs index 34b6f8a2..dee15432 100644 --- a/src/tracing.rs +++ b/src/tracing.rs @@ -38,15 +38,16 @@ where Wr: Writer, Cli: clap::Args, { - /// Initializes a global [`tracing::Subscriber`] with a default - /// [`fmt::Layer`] and [`LevelFilter::INFO`]. + /// Initializes a global [`tracing::Subscriber`] for this [`Cucumber`] with + /// a default [`fmt::Layer`] and [`LevelFilter::INFO`]. /// /// [`fmt::Layer`]: tracing_subscriber::fmt::Layer #[must_use] pub fn init_tracing(self) -> Self { self.configure_and_init_tracing( - format::DefaultFields::new(), - Format::default(), + tracing_subscriber::fmt::layer() + .fmt_fields(format::DefaultFields::new()) + .event_format(Format::default()), |layer| { tracing_subscriber::registry() .with(LevelFilter::INFO.and_then(layer)) @@ -54,8 +55,9 @@ where ) } - /// Configures a [`fmt::Layer`], additionally wraps it (for example, into a - /// [`LevelFilter`]), and initializes as a global [`tracing::Subscriber`]. + /// Configures the provided [`fmt::Layer`] for this [`Cucumber`] and allows + /// to additionally wrap it (for example, into a [`LevelFilter`]) before + /// initializing it as a global [`tracing::Subscriber`]. /// /// # Example /// @@ -63,7 +65,7 @@ where /// # use cucumber::{Cucumber, World as _}; /// # use tracing_subscriber::{ /// # filter::LevelFilter, - /// # fmt::format::{self, Format}, + /// # fmt::{self, format::{self, Format}}, /// # layer::SubscriberExt, /// # Layer, /// # }; @@ -74,11 +76,12 @@ where /// # let _ = async { /// World::cucumber() /// .configure_and_init_tracing( - /// format::DefaultFields::new(), - /// Format::default(), - /// |fmt_layer| { + /// fmt::layer() + /// .fmt_fields(format::DefaultFields::new()) + /// .event_format(Format::default()), + /// |layer| { /// tracing_subscriber::registry() - /// .with(LevelFilter::INFO.and_then(fmt_layer)) + /// .with(LevelFilter::INFO.and_then(layer)) /// }, /// ) /// .run_and_exit("./tests/features/doctests.feature") @@ -90,8 +93,7 @@ where #[must_use] pub fn configure_and_init_tracing( self, - fmt_fields: Fields, - event_format: Event, + fmt_layer: tracing_subscriber::fmt::Layer, configure: Conf, ) -> Self where @@ -118,9 +120,9 @@ where let (span_close_sender, span_close_receiver) = mpsc::unbounded(); let layer = RecordScenarioId::new(span_close_sender).and_then( - tracing_subscriber::fmt::layer() - .fmt_fields(SkipScenarioIdSpan(fmt_fields)) - .event_format(AppendScenarioMsg(event_format)) + fmt_layer + .map_fmt_fields(SkipScenarioIdSpan) + .map_event_format(AppendScenarioMsg) .with_writer(CollectorWriter::new(logs_sender)), ); Dispatch::new(configure(layer)).init(); diff --git a/tests/json.rs b/tests/json.rs index 0f39abec..a7332f5f 100644 --- a/tests/json.rs +++ b/tests/json.rs @@ -6,7 +6,10 @@ use regex::RegexBuilder; use tempfile::NamedTempFile; use tracing_subscriber::{ filter::LevelFilter, - fmt::format::{DefaultFields, Format}, + fmt::{ + self, + format::{DefaultFields, Format}, + }, layer::SubscriberExt as _, Layer as _, }; @@ -48,8 +51,9 @@ async fn test() { .fail_on_skipped() .with_default_cli() .configure_and_init_tracing( - DefaultFields::new(), - Format::default().with_ansi(false).without_time(), + fmt::layer().fmt_fields(DefaultFields::new()).event_format( + Format::default().with_ansi(false).without_time(), + ), |layer| { tracing_subscriber::registry() .with(LevelFilter::INFO.and_then(layer)) diff --git a/tests/junit.rs b/tests/junit.rs index 5b23d646..6fdce1e3 100644 --- a/tests/junit.rs +++ b/tests/junit.rs @@ -6,7 +6,10 @@ use regex::RegexBuilder; use tempfile::NamedTempFile; use tracing_subscriber::{ filter::LevelFilter, - fmt::format::{DefaultFields, Format}, + fmt::{ + self, + format::{DefaultFields, Format}, + }, layer::SubscriberExt as _, Layer as _, }; @@ -35,8 +38,9 @@ async fn output() { .fail_on_skipped() .with_default_cli() .configure_and_init_tracing( - DefaultFields::new(), - Format::default().with_ansi(false).without_time(), + fmt::layer().fmt_fields(DefaultFields::new()).event_format( + Format::default().with_ansi(false).without_time(), + ), |layer| { tracing_subscriber::registry() .with(LevelFilter::INFO.and_then(layer)) diff --git a/tests/tracing.rs b/tests/tracing.rs index c24dd5fb..cd1ab12c 100644 --- a/tests/tracing.rs +++ b/tests/tracing.rs @@ -7,7 +7,10 @@ use regex::Regex; use tokio::{spawn, time}; use tracing_subscriber::{ filter::LevelFilter, - fmt::format::{DefaultFields, Format}, + fmt::{ + self, + format::{DefaultFields, Format}, + }, layer::SubscriberExt as _, Layer, }; @@ -38,8 +41,9 @@ async fn main() { .fail_on_skipped() .with_default_cli() .configure_and_init_tracing( - DefaultFields::new(), - Format::default().with_ansi(false).without_time(), + fmt::layer().fmt_fields(DefaultFields::new()).event_format( + Format::default().with_ansi(false).without_time(), + ), |layer| { tracing_subscriber::registry() .with(LevelFilter::INFO.and_then(layer))