diff --git a/Cargo.lock b/Cargo.lock index 06ab4d1b32f6..4a373203a44f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -198,15 +198,6 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anstream" version = "0.6.4" @@ -3474,9 +3465,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f95b9abcae896730d42b78e09c155ed4ddf82c07b4de772c64aee5b2d8b7c150" +checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" dependencies = [ "bytes", "fnv", @@ -4827,9 +4818,9 @@ checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" [[package]] name = "matchers" -version = "0.0.1" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" dependencies = [ "regex-automata 0.1.10", ] @@ -5596,6 +5587,16 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num" version = "0.4.1" @@ -5771,6 +5772,12 @@ version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "p256" version = "0.11.1" @@ -11156,46 +11163,33 @@ dependencies = [ [[package]] name = "tracing-log" -version = "0.1.4" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" dependencies = [ "log", "once_cell", "tracing-core", ] -[[package]] -name = "tracing-serde" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" -dependencies = [ - "serde", - "tracing-core", -] - [[package]] name = "tracing-subscriber" -version = "0.2.25" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ - "ansi_term", "chrono", - "lazy_static", "matchers", - "parking_lot 0.11.2", + "nu-ansi-term", + "once_cell", + "parking_lot 0.12.1", "regex", - "serde", - "serde_json", "sharded-slab", "smallvec", "thread_local", "tracing", "tracing-core", "tracing-log", - "tracing-serde", ] [[package]] @@ -11386,7 +11380,7 @@ checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if", "digest 0.10.7", - "rand 0.7.3", + "rand 0.8.5", "static_assertions", ] diff --git a/substrate/client/executor/Cargo.toml b/substrate/client/executor/Cargo.toml index d1e7d7c9085a..d673c88dd5fb 100644 --- a/substrate/client/executor/Cargo.toml +++ b/substrate/client/executor/Cargo.toml @@ -41,7 +41,7 @@ sp-runtime = { path = "../../primitives/runtime" } sp-maybe-compressed-blob = { path = "../../primitives/maybe-compressed-blob" } sc-tracing = { path = "../tracing" } sp-tracing = { path = "../../primitives/tracing" } -tracing-subscriber = "0.2.19" +tracing-subscriber = "0.3.18" paste = "1.0" regex = "1.6.0" criterion = "0.4.0" diff --git a/substrate/client/tracing/Cargo.toml b/substrate/client/tracing/Cargo.toml index 9a3bb80e44c2..761b3c9dd1eb 100644 --- a/substrate/client/tracing/Cargo.toml +++ b/substrate/client/tracing/Cargo.toml @@ -24,8 +24,8 @@ rustc-hash = "1.1.0" serde = "1.0.188" thiserror = "1.0.48" tracing = "0.1.29" -tracing-log = "0.1.3" -tracing-subscriber = { version = "0.2.25", features = ["parking_lot"] } +tracing-log = "0.2" +tracing-subscriber = { version = "0.3.18", features = ["parking_lot"] } sc-client-api = { path = "../api" } sc-tracing-proc-macro = { path = "proc-macro" } sp-api = { path = "../../primitives/api" } @@ -37,6 +37,7 @@ sp-tracing = { path = "../../primitives/tracing" } [dev-dependencies] criterion = "0.4.0" +tracing-subscriber = { version = "0.3.18", features = ["chrono"] } [[bench]] name = "bench" diff --git a/substrate/client/tracing/benches/bench.rs b/substrate/client/tracing/benches/bench.rs index 69b2c0dd8ac6..a9bbb854f3b2 100644 --- a/substrate/client/tracing/benches/bench.rs +++ b/substrate/client/tracing/benches/bench.rs @@ -17,7 +17,10 @@ // limitations under the License. use criterion::{criterion_group, criterion_main, Criterion}; -use tracing_subscriber::fmt::time::{ChronoLocal, FormatTime}; +use tracing_subscriber::fmt::{ + format::Writer, + time::{ChronoLocal, FormatTime}, +}; fn bench_fast_local_time(c: &mut Criterion) { c.bench_function("fast_local_time", |b| { @@ -25,7 +28,7 @@ fn bench_fast_local_time(c: &mut Criterion) { let t = sc_tracing::logging::FastLocalTime { with_fractional: true }; b.iter(|| { buffer.clear(); - t.format_time(&mut buffer).unwrap(); + t.format_time(&mut Writer::new(&mut buffer)).unwrap(); }) }); } @@ -34,10 +37,10 @@ fn bench_fast_local_time(c: &mut Criterion) { fn bench_chrono_local(c: &mut Criterion) { c.bench_function("chrono_local", |b| { let mut buffer = String::new(); - let t = ChronoLocal::with_format("%Y-%m-%d %H:%M:%S%.3f".to_string()); + let t = ChronoLocal::new("%Y-%m-%d %H:%M:%S%.3f".to_string()); b.iter(|| { buffer.clear(); - t.format_time(&mut buffer).unwrap(); + t.format_time(&mut Writer::new(&mut buffer)).unwrap(); }) }); } diff --git a/substrate/client/tracing/src/lib.rs b/substrate/client/tracing/src/lib.rs index 8a61f5498385..f8e44aa6de63 100644 --- a/substrate/client/tracing/src/lib.rs +++ b/substrate/client/tracing/src/lib.rs @@ -291,7 +291,7 @@ impl Layer for ProfilingLayer where S: Subscriber + for<'span> LookupSpan<'span>, { - fn new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context) { + fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context) { if let Some(span) = ctx.span(id) { let mut extension = span.extensions_mut(); let parent_id = attrs.parent().cloned().or_else(|| { diff --git a/substrate/client/tracing/src/logging/event_format.rs b/substrate/client/tracing/src/logging/event_format.rs index 3b0e9edd4cbe..99baed5601d8 100644 --- a/substrate/client/tracing/src/logging/event_format.rs +++ b/substrate/client/tracing/src/logging/event_format.rs @@ -25,7 +25,7 @@ use tracing::{Event, Level, Subscriber}; use tracing_log::NormalizeEvent; use tracing_subscriber::{ field::RecordFields, - fmt::{time::FormatTime, FmtContext, FormatEvent, FormatFields}, + fmt::{format::Writer, time::FormatTime, FmtContext, FormatEvent, FormatFields}, layer::Context, registry::{LookupSpan, SpanRef}, }; @@ -56,14 +56,14 @@ where pub(crate) fn format_event_custom<'b, S, N>( &self, ctx: CustomFmtContext<'b, S, N>, - writer: &mut dyn fmt::Write, + mut writer: Writer<'_>, event: &Event, ) -> fmt::Result where S: Subscriber + for<'a> LookupSpan<'a>, N: for<'a> FormatFields<'a> + 'static, { - let writer = &mut ControlCodeSanitizer::new(!self.enable_color, writer); + let writer = &mut ControlCodeSanitizer::new(!self.enable_color, &mut writer); let normalized_meta = event.normalized_metadata(); let meta = normalized_meta.as_ref().unwrap_or_else(|| event.metadata()); time::write(&self.timer, writer, self.enable_color)?; @@ -109,7 +109,7 @@ where writer.sanitize = true; } - ctx.format_fields(writer, event)?; + ctx.format_fields(Writer::new(writer), event)?; writeln!(writer)?; writer.flush() @@ -128,7 +128,7 @@ where fn format_event( &self, ctx: &FmtContext, - writer: &mut dyn fmt::Write, + mut writer: Writer<'_>, event: &Event, ) -> fmt::Result { if self.dup_to_stdout && @@ -137,7 +137,11 @@ where event.metadata().level() == &Level::ERROR) { let mut out = String::new(); - self.format_event_custom(CustomFmtContext::FmtContext(ctx), &mut out, event)?; + self.format_event_custom( + CustomFmtContext::FmtContext(ctx), + Writer::new(&mut out), + event, + )?; writer.write_str(&out)?; print!("{}", out); Ok(()) @@ -242,19 +246,23 @@ impl<'a> fmt::Display for FmtThreadName<'a> { mod time { use anstyle::Style; use std::fmt; - use tracing_subscriber::fmt::time::FormatTime; + use tracing_subscriber::fmt::{format::Writer, time::FormatTime}; - pub(crate) fn write(timer: T, writer: &mut dyn fmt::Write, with_ansi: bool) -> fmt::Result + pub(crate) fn write( + timer: T, + writer: &mut (impl Sized + fmt::Write), + with_ansi: bool, + ) -> fmt::Result where T: FormatTime, { if with_ansi { let style = Style::new().dimmed(); write!(writer, "{}", style.render())?; - timer.format_time(writer)?; + timer.format_time(&mut Writer::new(writer))?; write!(writer, "{}", style.render_reset())?; } else { - timer.format_time(writer)?; + timer.format_time(&mut Writer::new(writer))?; } writer.write_char(' ')?; Ok(()) @@ -274,11 +282,7 @@ where S: Subscriber + for<'lookup> LookupSpan<'lookup>, N: for<'writer> FormatFields<'writer> + 'static, { - fn format_fields( - &self, - writer: &'a mut dyn fmt::Write, - fields: R, - ) -> fmt::Result { + fn format_fields(&self, writer: Writer<'a>, fields: R) -> fmt::Result { match self { CustomFmtContext::FmtContext(fmt_ctx) => fmt_ctx.format_fields(writer, fields), CustomFmtContext::ContextWithFormatFields(_ctx, fmt_fields) => diff --git a/substrate/client/tracing/src/logging/fast_local_time.rs b/substrate/client/tracing/src/logging/fast_local_time.rs index 7398b76a7e25..28bf1173743e 100644 --- a/substrate/client/tracing/src/logging/fast_local_time.rs +++ b/substrate/client/tracing/src/logging/fast_local_time.rs @@ -19,7 +19,7 @@ use chrono::{Datelike, Timelike}; use std::{cell::RefCell, fmt::Write, time::SystemTime}; -use tracing_subscriber::fmt::time::FormatTime; +use tracing_subscriber::fmt::{format::Writer, time::FormatTime}; /// A structure which, when `Display`d, will print out the current local time. #[derive(Debug, Clone, Copy, Eq, PartialEq, Default)] @@ -77,7 +77,7 @@ thread_local! { } impl FormatTime for FastLocalTime { - fn format_time(&self, w: &mut dyn Write) -> std::fmt::Result { + fn format_time(&self, w: &mut Writer<'_>) -> std::fmt::Result { const TIMESTAMP_PARTIAL_LENGTH: usize = "0000-00-00 00:00:00".len(); let elapsed = SystemTime::now() @@ -130,7 +130,7 @@ impl FormatTime for FastLocalTime { impl std::fmt::Display for FastLocalTime { fn fmt(&self, w: &mut std::fmt::Formatter) -> std::fmt::Result { - self.format_time(w) + self.format_time(&mut Writer::new(w)) } } diff --git a/substrate/client/tracing/src/logging/layers/prefix_layer.rs b/substrate/client/tracing/src/logging/layers/prefix_layer.rs index bf740d495fa3..a0d7e7fb5a92 100644 --- a/substrate/client/tracing/src/logging/layers/prefix_layer.rs +++ b/substrate/client/tracing/src/logging/layers/prefix_layer.rs @@ -33,7 +33,7 @@ impl Layer for PrefixLayer where S: Subscriber + for<'a> LookupSpan<'a>, { - fn new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) { + fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) { let span = match ctx.span(id) { Some(span) => span, None => { diff --git a/substrate/client/tracing/src/logging/mod.rs b/substrate/client/tracing/src/logging/mod.rs index 61df0de8c64c..7489724b7915 100644 --- a/substrate/client/tracing/src/logging/mod.rs +++ b/substrate/client/tracing/src/logging/mod.rs @@ -104,7 +104,7 @@ fn prepare_subscriber( where N: for<'writer> FormatFields<'writer> + 'static, E: FormatEvent + 'static, - W: MakeWriter + 'static, + W: for<'a> MakeWriter<'a> + 'static, F: layer::Layer> + Send + Sync + 'static, FmtLayer: layer::Layer + Send + Sync + 'static, { diff --git a/substrate/client/tracing/src/logging/stderr_writer.rs b/substrate/client/tracing/src/logging/stderr_writer.rs index 6940f2cc68b0..7334e1b16d64 100644 --- a/substrate/client/tracing/src/logging/stderr_writer.rs +++ b/substrate/client/tracing/src/logging/stderr_writer.rs @@ -149,7 +149,7 @@ impl Default for MakeStderrWriter { } } -impl tracing_subscriber::fmt::MakeWriter for MakeStderrWriter { +impl<'a> tracing_subscriber::fmt::MakeWriter<'a> for MakeStderrWriter { type Writer = StderrWriter; fn make_writer(&self) -> Self::Writer { diff --git a/substrate/primitives/tracing/Cargo.toml b/substrate/primitives/tracing/Cargo.toml index 0f7e217ec388..a3efcc0b2a16 100644 --- a/substrate/primitives/tracing/Cargo.toml +++ b/substrate/primitives/tracing/Cargo.toml @@ -24,9 +24,7 @@ codec = { version = "3.6.1", package = "parity-scale-codec", default-features = ] } tracing = { version = "0.1.29", default-features = false } tracing-core = { version = "0.1.28", default-features = false } -tracing-subscriber = { version = "0.2.25", optional = true, features = [ - "tracing-log", -] } +tracing-subscriber = { version = "0.3.18", optional = true, features = ["env-filter"] } [features] default = [ "std" ]