Skip to content

Commit

Permalink
tracing-subscriber 0.3.18
Browse files Browse the repository at this point in the history
Resolves https://github.com/serai-dex/serai/228 (once Serai moves over to this
repo).
  • Loading branch information
kayabaNerve committed Nov 13, 2023
1 parent 11242e4 commit 0795e37
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 66 deletions.
62 changes: 28 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion substrate/client/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions substrate/client/tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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"
Expand Down
11 changes: 7 additions & 4 deletions substrate/client/tracing/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
// 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| {
let mut buffer = String::new();
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();
})
});
}
Expand All @@ -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();
})
});
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl<S> Layer<S> for ProfilingLayer
where
S: Subscriber + for<'span> LookupSpan<'span>,
{
fn new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<S>) {
fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<S>) {
if let Some(span) = ctx.span(id) {
let mut extension = span.extensions_mut();
let parent_id = attrs.parent().cloned().or_else(|| {
Expand Down
34 changes: 19 additions & 15 deletions substrate/client/tracing/src/logging/event_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -109,7 +109,7 @@ where
writer.sanitize = true;
}

ctx.format_fields(writer, event)?;
ctx.format_fields(Writer::new(writer), event)?;
writeln!(writer)?;

writer.flush()
Expand All @@ -128,7 +128,7 @@ where
fn format_event(
&self,
ctx: &FmtContext<S, N>,
writer: &mut dyn fmt::Write,
mut writer: Writer<'_>,
event: &Event,
) -> fmt::Result {
if self.dup_to_stdout &&
Expand All @@ -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(())
Expand Down Expand Up @@ -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<T>(timer: T, writer: &mut dyn fmt::Write, with_ansi: bool) -> fmt::Result
pub(crate) fn write<T>(
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(())
Expand All @@ -274,11 +282,7 @@ where
S: Subscriber + for<'lookup> LookupSpan<'lookup>,
N: for<'writer> FormatFields<'writer> + 'static,
{
fn format_fields<R: RecordFields>(
&self,
writer: &'a mut dyn fmt::Write,
fields: R,
) -> fmt::Result {
fn format_fields<R: RecordFields>(&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) =>
Expand Down
6 changes: 3 additions & 3 deletions substrate/client/tracing/src/logging/fast_local_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<S> Layer<S> 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 => {
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/tracing/src/logging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn prepare_subscriber<N, E, F, W>(
where
N: for<'writer> FormatFields<'writer> + 'static,
E: FormatEvent<Registry, N> + 'static,
W: MakeWriter + 'static,
W: for<'a> MakeWriter<'a> + 'static,
F: layer::Layer<Formatter<N, E, W>> + Send + Sync + 'static,
FmtLayer<Registry, N, E, W>: layer::Layer<Registry> + Send + Sync + 'static,
{
Expand Down
2 changes: 1 addition & 1 deletion substrate/client/tracing/src/logging/stderr_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions substrate/primitives/tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down

0 comments on commit 0795e37

Please sign in to comment.