From 70c2379543ca141b097c42ce70222dd3246228dd Mon Sep 17 00:00:00 2001 From: james7132 Date: Tue, 23 Apr 2024 01:07:04 -0700 Subject: [PATCH 1/2] Remove once_cell as a dependency --- tracing-core/Cargo.toml | 3 +- tracing-core/src/callsite.rs | 5 +- tracing-flame/Cargo.toml | 3 +- tracing-flame/src/lib.rs | 12 ++-- tracing-log/Cargo.toml | 3 +- tracing-log/src/lib.rs | 66 +++++++++++++------ tracing-subscriber/Cargo.toml | 5 +- .../src/filter/env/directive.rs | 32 +++++---- tracing-subscriber/src/lib.rs | 4 +- 9 files changed, 82 insertions(+), 51 deletions(-) diff --git a/tracing-core/Cargo.toml b/tracing-core/Cargo.toml index c56b59f262..5c6f2f7d4b 100644 --- a/tracing-core/Cargo.toml +++ b/tracing-core/Cargo.toml @@ -29,13 +29,12 @@ rust-version = "1.63.0" [features] default = ["std"] alloc = [] -std = ["once_cell", "alloc"] +std = ["alloc"] [badges] maintenance = { status = "actively-developed" } [dependencies] -once_cell = { version = "1.13.0", optional = true } [package.metadata.docs.rs] all-features = true diff --git a/tracing-core/src/callsite.rs b/tracing-core/src/callsite.rs index 9dd6663b20..83d4d0cdfc 100644 --- a/tracing-core/src/callsite.rs +++ b/tracing-core/src/callsite.rs @@ -167,7 +167,6 @@ pub use self::inner::{rebuild_interest_cache, register}; #[cfg(feature = "std")] mod inner { use super::*; - use once_cell::sync::Lazy; use std::sync::RwLock; use std::vec::Vec; @@ -178,10 +177,10 @@ mod inner { dispatchers: RwLock, } - static REGISTRY: Lazy = Lazy::new(|| Registry { + static REGISTRY: Registry = Registry { callsites: LinkedList::new(), dispatchers: RwLock::new(Vec::new()), - }); + }; /// Clear and reregister interest on every [`Callsite`] /// diff --git a/tracing-flame/Cargo.toml b/tracing-flame/Cargo.toml index 597aefe668..0038c3de9b 100644 --- a/tracing-flame/Cargo.toml +++ b/tracing-flame/Cargo.toml @@ -19,7 +19,7 @@ categories = [ "asynchronous", ] keywords = ["tracing", "subscriber", "flamegraph", "profiling"] -rust-version = "1.63.0" +rust-version = "1.70.0" [features] default = ["smallvec"] @@ -28,7 +28,6 @@ smallvec = ["tracing-subscriber/smallvec"] [dependencies] tracing-subscriber = { path = "../tracing-subscriber", version = "0.3", default-features = false, features = ["registry", "fmt"] } tracing = { path = "../tracing", version = "0.2", default-features = false, features = ["std"] } -once_cell = "1.13.0" [dev-dependencies] tempfile = "3.3.0" diff --git a/tracing-flame/src/lib.rs b/tracing-flame/src/lib.rs index 5ad84b582c..7fcd0686da 100644 --- a/tracing-flame/src/lib.rs +++ b/tracing-flame/src/lib.rs @@ -10,7 +10,7 @@ //! issues bottlenecks in an application. For more details, see Brendan Gregg's [post] //! on flamegraphs. //! -//! *Compiler support: [requires `rustc` 1.63+][msrv]* +//! *Compiler support: [requires `rustc` 1.70+][msrv]* //! //! [msrv]: #supported-rust-versions //! [post]: http://www.brendangregg.com/flamegraphs.html @@ -95,7 +95,7 @@ //! ## Supported Rust Versions //! //! Tracing is built against the latest stable release. The minimum supported -//! version is 1.63. The current Tracing version is not guaranteed to build on +//! version is 1.70. The current Tracing version is not guaranteed to build on //! Rust versions earlier than the minimum supported version. //! //! Tracing follows the same compiler support policies as the rest of the Tokio @@ -136,7 +136,6 @@ use error::Error; use error::Kind; -use once_cell::sync::Lazy; use std::cell::Cell; use std::fmt; use std::fmt::Write as _; @@ -147,6 +146,7 @@ use std::marker::PhantomData; use std::path::Path; use std::sync::Arc; use std::sync::Mutex; +use std::sync::OnceLock; use std::time::{Duration, Instant}; use tracing::span; use tracing::Collect; @@ -157,10 +157,10 @@ use tracing_subscriber::Subscribe; mod error; -static START: Lazy = Lazy::new(Instant::now); +static START: OnceLock = OnceLock::new(); thread_local! { - static LAST_EVENT: Cell = Cell::new(*START); + static LAST_EVENT: Cell = Cell::new(*START.get_or_init(Instant::now)); static THREAD_NAME: String = { let thread = std::thread::current(); @@ -264,7 +264,7 @@ where pub fn new(writer: W) -> Self { // Initialize the start used by all threads when initializing the // LAST_EVENT when constructing the subscriber - let _unused = *START; + let _unused = START.get_or_init(Instant::now); Self { out: Arc::new(Mutex::new(writer)), config: Default::default(), diff --git a/tracing-log/Cargo.toml b/tracing-log/Cargo.toml index 8e51f2561c..d27032746f 100644 --- a/tracing-log/Cargo.toml +++ b/tracing-log/Cargo.toml @@ -15,7 +15,7 @@ categories = [ keywords = ["logging", "tracing", "log"] license = "MIT" readme = "README.md" -rust-version = "1.63.0" +rust-version = "1.70.0" [features] default = ["log-tracer", "std"] @@ -25,7 +25,6 @@ log-tracer = [] [dependencies] tracing-core = { path = "../tracing-core", version = "0.2"} log = "0.4.17" -once_cell = "1.13.0" env_logger = { version = "0.8.4", optional = true } [dev-dependencies] diff --git a/tracing-log/src/lib.rs b/tracing-log/src/lib.rs index dbdf8e9549..9fbc1df442 100644 --- a/tracing-log/src/lib.rs +++ b/tracing-log/src/lib.rs @@ -16,7 +16,7 @@ //! - An [`env_logger`] module, with helpers for using the [`env_logger` crate] //! with `tracing` (optional, enabled by the `env-logger` feature). //! -//! *Compiler support: [requires `rustc` 1.63+][msrv]* +//! *Compiler support: [requires `rustc` 1.70+][msrv]* //! //! [msrv]: #supported-rust-versions //! @@ -76,7 +76,7 @@ //! ## Supported Rust Versions //! //! Tracing is built against the latest stable release. The minimum supported -//! version is 1.63. The current Tracing version is not guaranteed to build on +//! version is 1.70. The current Tracing version is not guaranteed to build on //! Rust versions earlier than the minimum supported version. //! //! Tracing follows the same compiler support policies as the rest of the Tokio @@ -124,9 +124,8 @@ unused_parens, while_true )] -use once_cell::sync::Lazy; -use std::{fmt, io}; +use std::{fmt, io, sync::OnceLock}; use tracing_core::{ callsite::{self, Callsite}, @@ -318,19 +317,28 @@ log_cs!( ErrorCallsite ); -static TRACE_FIELDS: Lazy = Lazy::new(|| Fields::new(&TRACE_CS)); -static DEBUG_FIELDS: Lazy = Lazy::new(|| Fields::new(&DEBUG_CS)); -static INFO_FIELDS: Lazy = Lazy::new(|| Fields::new(&INFO_CS)); -static WARN_FIELDS: Lazy = Lazy::new(|| Fields::new(&WARN_CS)); -static ERROR_FIELDS: Lazy = Lazy::new(|| Fields::new(&ERROR_CS)); +static TRACE_FIELDS: OnceLock = OnceLock::new(); +static DEBUG_FIELDS: OnceLock = OnceLock::new(); +static INFO_FIELDS: OnceLock = OnceLock::new(); +static WARN_FIELDS: OnceLock = OnceLock::new(); +static ERROR_FIELDS: OnceLock = OnceLock::new(); fn level_to_cs(level: Level) -> (&'static dyn Callsite, &'static Fields) { match level { - Level::TRACE => (&TRACE_CS, &*TRACE_FIELDS), - Level::DEBUG => (&DEBUG_CS, &*DEBUG_FIELDS), - Level::INFO => (&INFO_CS, &*INFO_FIELDS), - Level::WARN => (&WARN_CS, &*WARN_FIELDS), - Level::ERROR => (&ERROR_CS, &*ERROR_FIELDS), + Level::TRACE => ( + &TRACE_CS, + TRACE_FIELDS.get_or_init(|| Fields::new(&TRACE_CS)), + ), + Level::DEBUG => ( + &DEBUG_CS, + DEBUG_FIELDS.get_or_init(|| Fields::new(&DEBUG_CS)), + ), + Level::INFO => (&INFO_CS, INFO_FIELDS.get_or_init(|| Fields::new(&INFO_CS))), + Level::WARN => (&WARN_CS, WARN_FIELDS.get_or_init(|| Fields::new(&WARN_CS))), + Level::ERROR => ( + &ERROR_CS, + ERROR_FIELDS.get_or_init(|| Fields::new(&ERROR_CS)), + ), } } @@ -342,11 +350,31 @@ fn loglevel_to_cs( &'static Metadata<'static>, ) { match level { - log::Level::Trace => (&TRACE_CS, &*TRACE_FIELDS, &TRACE_META), - log::Level::Debug => (&DEBUG_CS, &*DEBUG_FIELDS, &DEBUG_META), - log::Level::Info => (&INFO_CS, &*INFO_FIELDS, &INFO_META), - log::Level::Warn => (&WARN_CS, &*WARN_FIELDS, &WARN_META), - log::Level::Error => (&ERROR_CS, &*ERROR_FIELDS, &ERROR_META), + log::Level::Trace => ( + &TRACE_CS, + TRACE_FIELDS.get_or_init(|| Fields::new(&TRACE_CS)), + &TRACE_META, + ), + log::Level::Debug => ( + &DEBUG_CS, + DEBUG_FIELDS.get_or_init(|| Fields::new(&DEBUG_CS)), + &DEBUG_META, + ), + log::Level::Info => ( + &INFO_CS, + INFO_FIELDS.get_or_init(|| Fields::new(&INFO_CS)), + &INFO_META, + ), + log::Level::Warn => ( + &WARN_CS, + WARN_FIELDS.get_or_init(|| Fields::new(&WARN_CS)), + &WARN_META, + ), + log::Level::Error => ( + &ERROR_CS, + ERROR_FIELDS.get_or_init(|| Fields::new(&ERROR_CS)), + &ERROR_META, + ), } } diff --git a/tracing-subscriber/Cargo.toml b/tracing-subscriber/Cargo.toml index 524bf4b482..b8330c629d 100644 --- a/tracing-subscriber/Cargo.toml +++ b/tracing-subscriber/Cargo.toml @@ -20,14 +20,14 @@ categories = [ "asynchronous", ] keywords = ["logging", "tracing", "metrics", "subscriber"] -rust-version = "1.63.0" +rust-version = "1.70.0" [features] default = ["smallvec", "fmt", "ansi", "tracing-log", "std"] alloc = ["tracing-core/alloc"] std = ["alloc", "tracing-core/std"] -env-filter = ["matchers", "regex", "once_cell", "tracing", "std", "thread_local"] +env-filter = ["matchers", "regex", "tracing", "std", "thread_local"] fmt = ["registry", "std"] ansi = ["fmt", "nu-ansi-term"] registry = ["sharded-slab", "thread_local", "std"] @@ -45,7 +45,6 @@ tracing = { optional = true, path = "../tracing", version = "0.2", default-featu matchers = { optional = true, version = "0.1.0" } regex = { optional = true, version = "1.6.0", default-features = false, features = ["std", "unicode-case", "unicode-perl"] } smallvec = { optional = true, version = "1.9.0" } -once_cell = { optional = true, version = "1.13.0" } # fmt tracing-log = { path = "../tracing-log", version = "0.2", optional = true, default-features = false, features = ["log-tracer", "std"] } diff --git a/tracing-subscriber/src/filter/env/directive.rs b/tracing-subscriber/src/filter/env/directive.rs index 1f0b118661..2412e17f71 100644 --- a/tracing-subscriber/src/filter/env/directive.rs +++ b/tracing-subscriber/src/filter/env/directive.rs @@ -4,9 +4,8 @@ use crate::filter::{ env::{field, FieldMap}, level::LevelFilter, }; -use once_cell::sync::Lazy; -use regex::Regex; -use std::{cmp::Ordering, fmt, iter::FromIterator, str::FromStr}; +use regex::{Regex, bytes::Regex}; +use std::{cmp::Ordering, fmt, iter::FromIterator, str::FromStr, sync::OnceLock}; use tracing_core::{span, Level, Metadata}; /// A single filtering directive. @@ -120,7 +119,11 @@ impl Directive { } pub(super) fn parse(from: &str, regex: bool) -> Result { - static DIRECTIVE_RE: Lazy = Lazy::new(|| { + static DIRECTIVE_RE: OnceLock = OnceLock::new(); + static SPAN_PART_RE: OnceLock = OnceLock::new(); + static FIELD_FILTER_RE: OnceLock = OnceLock::new(); + + fn directive_re() -> Regex { Regex::new( r"(?x) ^(?P(?i:trace|debug|info|warn|error|off|[0-5]))$ | @@ -139,13 +142,15 @@ impl Directive { ", ) .unwrap() - }); - static SPAN_PART_RE: Lazy = - Lazy::new(|| Regex::new(r"(?P[^\]\{]+)?(?:\{(?P[^\}]*)\})?").unwrap()); - static FIELD_FILTER_RE: Lazy = + } + + fn span_part_re() -> Regex { + Regex::new(r"(?P[^\]\{]+)?(?:\{(?P[^\}]*)\})?").unwrap() + } + + fn field_filter_re() -> Regex { // TODO(eliza): this doesn't _currently_ handle value matchers that include comma // characters. We should fix that. - Lazy::new(|| { Regex::new( r"(?x) ( @@ -159,9 +164,11 @@ impl Directive { ", ) .unwrap() - }); + } - let caps = DIRECTIVE_RE.captures(from).ok_or_else(ParseError::new)?; + let caps = DIRECTIVE_RE + .get_or_init(directive_re) + .captures(from).ok_or_else(ParseError::new)?; if let Some(level) = caps .name("global_level") @@ -186,12 +193,13 @@ impl Directive { .name("span") .and_then(|cap| { let cap = cap.as_str().trim_matches(|c| c == '[' || c == ']'); - let caps = SPAN_PART_RE.captures(cap)?; + let caps = SPAN_PART_RE.get_or_init(span_part_re).captures(cap)?; let span = caps.name("name").map(|c| c.as_str().to_owned()); let fields = caps .name("fields") .map(|c| { FIELD_FILTER_RE + .get_or_init(field_filter_re) .find_iter(c.as_str()) .map(|c| field::Match::parse(c.as_str(), regex)) .collect::, _>>() diff --git a/tracing-subscriber/src/lib.rs b/tracing-subscriber/src/lib.rs index 4b1ce72d82..c9bbfe8dc7 100644 --- a/tracing-subscriber/src/lib.rs +++ b/tracing-subscriber/src/lib.rs @@ -10,7 +10,7 @@ //! `tracing-subscriber` is intended for use by both `Collector` authors and //! application authors using `tracing` to instrument their applications. //! -//! *Compiler support: [requires `rustc` 1.63+][msrv]* +//! *Compiler support: [requires `rustc` 1.70+][msrv]* //! //! [msrv]: #supported-rust-versions //! @@ -106,7 +106,7 @@ //! ## Supported Rust Versions //! //! Tracing is built against the latest stable release. The minimum supported -//! version is 1.63. The current Tracing version is not guaranteed to build on +//! version is 1.70. The current Tracing version is not guaranteed to build on //! Rust versions earlier than the minimum supported version. //! //! Tracing follows the same compiler support policies as the rest of the Tokio From a0bcb48c97bd16cca7529f35ae053f1213f1d1e3 Mon Sep 17 00:00:00 2001 From: james7132 Date: Tue, 23 Apr 2024 01:11:34 -0700 Subject: [PATCH 2/2] Fix cargo check --- tracing-subscriber/src/filter/env/directive.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracing-subscriber/src/filter/env/directive.rs b/tracing-subscriber/src/filter/env/directive.rs index 2412e17f71..c351903a46 100644 --- a/tracing-subscriber/src/filter/env/directive.rs +++ b/tracing-subscriber/src/filter/env/directive.rs @@ -4,7 +4,7 @@ use crate::filter::{ env::{field, FieldMap}, level::LevelFilter, }; -use regex::{Regex, bytes::Regex}; +use regex::Regex; use std::{cmp::Ordering, fmt, iter::FromIterator, str::FromStr, sync::OnceLock}; use tracing_core::{span, Level, Metadata};