Skip to content

Commit

Permalink
Remove once_cell as a dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
james7132 committed Apr 23, 2024
1 parent 908cc43 commit 70c2379
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 51 deletions.
3 changes: 1 addition & 2 deletions tracing-core/Cargo.toml
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions tracing-core/src/callsite.rs
Expand Up @@ -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;

Expand All @@ -178,10 +177,10 @@ mod inner {
dispatchers: RwLock<Dispatchers>,
}

static REGISTRY: Lazy<Registry> = Lazy::new(|| Registry {
static REGISTRY: Registry = Registry {
callsites: LinkedList::new(),
dispatchers: RwLock::new(Vec::new()),
});
};

/// Clear and reregister interest on every [`Callsite`]
///
Expand Down
3 changes: 1 addition & 2 deletions tracing-flame/Cargo.toml
Expand Up @@ -19,7 +19,7 @@ categories = [
"asynchronous",
]
keywords = ["tracing", "subscriber", "flamegraph", "profiling"]
rust-version = "1.63.0"
rust-version = "1.70.0"

[features]
default = ["smallvec"]
Expand All @@ -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"
12 changes: 6 additions & 6 deletions tracing-flame/src/lib.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 _;
Expand All @@ -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;
Expand All @@ -157,10 +157,10 @@ use tracing_subscriber::Subscribe;

mod error;

static START: Lazy<Instant> = Lazy::new(Instant::now);
static START: OnceLock<Instant> = OnceLock::new();

thread_local! {
static LAST_EVENT: Cell<Instant> = Cell::new(*START);
static LAST_EVENT: Cell<Instant> = Cell::new(*START.get_or_init(Instant::now));

static THREAD_NAME: String = {
let thread = std::thread::current();
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 1 addition & 2 deletions tracing-log/Cargo.toml
Expand Up @@ -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"]
Expand All @@ -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]
Expand Down
66 changes: 47 additions & 19 deletions tracing-log/src/lib.rs
Expand Up @@ -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
//!
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -318,19 +317,28 @@ log_cs!(
ErrorCallsite
);

static TRACE_FIELDS: Lazy<Fields> = Lazy::new(|| Fields::new(&TRACE_CS));
static DEBUG_FIELDS: Lazy<Fields> = Lazy::new(|| Fields::new(&DEBUG_CS));
static INFO_FIELDS: Lazy<Fields> = Lazy::new(|| Fields::new(&INFO_CS));
static WARN_FIELDS: Lazy<Fields> = Lazy::new(|| Fields::new(&WARN_CS));
static ERROR_FIELDS: Lazy<Fields> = Lazy::new(|| Fields::new(&ERROR_CS));
static TRACE_FIELDS: OnceLock<Fields> = OnceLock::new();
static DEBUG_FIELDS: OnceLock<Fields> = OnceLock::new();
static INFO_FIELDS: OnceLock<Fields> = OnceLock::new();
static WARN_FIELDS: OnceLock<Fields> = OnceLock::new();
static ERROR_FIELDS: OnceLock<Fields> = 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)),
),
}
}

Expand All @@ -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,
),
}
}

Expand Down
5 changes: 2 additions & 3 deletions tracing-subscriber/Cargo.toml
Expand Up @@ -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"]
Expand All @@ -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"] }
Expand Down
32 changes: 20 additions & 12 deletions tracing-subscriber/src/filter/env/directive.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -120,7 +119,11 @@ impl Directive {
}

pub(super) fn parse(from: &str, regex: bool) -> Result<Self, ParseError> {
static DIRECTIVE_RE: Lazy<Regex> = Lazy::new(|| {
static DIRECTIVE_RE: OnceLock<Regex> = OnceLock::new();
static SPAN_PART_RE: OnceLock<Regex> = OnceLock::new();
static FIELD_FILTER_RE: OnceLock<Regex> = OnceLock::new();

fn directive_re() -> Regex {
Regex::new(
r"(?x)
^(?P<global_level>(?i:trace|debug|info|warn|error|off|[0-5]))$ |
Expand All @@ -139,13 +142,15 @@ impl Directive {
",
)
.unwrap()
});
static SPAN_PART_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(?P<name>[^\]\{]+)?(?:\{(?P<fields>[^\}]*)\})?").unwrap());
static FIELD_FILTER_RE: Lazy<Regex> =
}

fn span_part_re() -> Regex {
Regex::new(r"(?P<name>[^\]\{]+)?(?:\{(?P<fields>[^\}]*)\})?").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)
(
Expand All @@ -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")
Expand All @@ -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::<Result<Vec<_>, _>>()
Expand Down
4 changes: 2 additions & 2 deletions tracing-subscriber/src/lib.rs
Expand Up @@ -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
//!
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 70c2379

Please sign in to comment.