Skip to content

Commit

Permalink
chore: rename layers to subscribers and fix some typos (#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
Folyd authored Mar 4, 2021
1 parent ba7a7f7 commit fe59f77
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 71 deletions.
2 changes: 1 addition & 1 deletion examples/examples/thread-info.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![deny(rust_2018_idioms)]
/// This is a example showing how thread info can be displayed when
/// formatting events with `tracing_subscriber::fmt`. This is useful
/// as `tracing` spans can be entered by multicple threads concurrently,
/// as `tracing` spans can be entered by multiple threads concurrently,
/// or move across threads freely.
///
/// You can run this example by running the following command in a terminal
Expand Down
2 changes: 1 addition & 1 deletion tracing-appender/src/non_blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub struct WorkerGuard {
///
/// This struct implements [`MakeWriter`][make_writer] from the `tracing-subscriber`
/// crate. Therefore, it can be used with the [`tracing_subscriber::fmt`][fmt] module
/// or with any other subscriber/layer implementation that uses the `MakeWriter` trait.
/// or with any other collector/subscriber implementation that uses the `MakeWriter` trait.
///
/// [make_writer]: tracing_subscriber::fmt::MakeWriter
/// [fmt]: mod@tracing_subscriber::fmt
Expand Down
6 changes: 3 additions & 3 deletions tracing-core/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub trait Collect: 'static {
/// never be enabled unless a new collector expresses interest in it.
///
/// `Collector`s which require their filters to be run every time an event
/// occurs or a span is entered::exited should return `Interest::sometimes`.
/// occurs or a span is entered/exited should return `Interest::sometimes`.
/// If a collector returns `Interest::sometimes`, then its' [`enabled`] method
/// will be called every time an event or span is created from that callsite.
///
Expand Down Expand Up @@ -135,7 +135,7 @@ pub trait Collect: 'static {
/// [filter]: Self::enabled
/// [metadata]: super::metadata::Metadata
/// [`enabled`]: Self::enabled
/// [`rebuild_interest_cache`]: super::callsite::fn.rebuild_interest_cache.html
/// [`rebuild_interest_cache`]: super::callsite::rebuild_interest_cache
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
if self.enabled(metadata) {
Interest::always()
Expand Down Expand Up @@ -186,7 +186,7 @@ pub trait Collect: 'static {
/// level changes.
///
/// [level]: super::Level
/// [rebuild]: super::callsite::fn.rebuild_interest_cache.html
/// [rebuild]: super::callsite::rebuild_interest_cache
fn max_level_hint(&self) -> Option<LevelFilter> {
None
}
Expand Down
2 changes: 1 addition & 1 deletion tracing-error/src/backtrace.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::layer::WithContext;
use crate::subscriber::WithContext;
use std::fmt;
use tracing::{Metadata, Span};

Expand Down
8 changes: 4 additions & 4 deletions tracing-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//!
//! * [`SpanTrace`], a captured trace of the current `tracing` [span] context
//!
//! * [`ErrorSubscriber`], a [subscriber layer] which enables capturing `SpanTrace`s
//! * [`ErrorSubscriber`], a [subscriber] which enables capturing `SpanTrace`s
//!
//! **Note**: This crate is currently experimental.
//!
Expand Down Expand Up @@ -161,7 +161,7 @@
//! [span]: mod@tracing::span
//! [events]: tracing::Event
//! [collector]: tracing::Collect
//! [subscriber layer]: tracing_subscriber::subscribe::Subscribe
//! [subscriber]: tracing_subscriber::subscribe::Subscribe
//!
//! ## Supported Rust Versions
//!
Expand Down Expand Up @@ -209,12 +209,12 @@
mod backtrace;
#[cfg(feature = "traced-error")]
mod error;
mod layer;
mod subscriber;

pub use self::backtrace::{SpanTrace, SpanTraceStatus};
#[cfg(feature = "traced-error")]
pub use self::error::{ExtractSpanTrace, InstrumentError, InstrumentResult, TracedError};
pub use self::layer::ErrorSubscriber;
pub use self::subscriber::ErrorSubscriber;

#[cfg(feature = "traced-error")]
#[cfg_attr(docsrs, doc(cfg(feature = "traced-error")))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where
S: Collect + for<'span> LookupSpan<'span>,
F: for<'writer> FormatFields<'writer> + 'static,
{
/// Notifies this layer that a new span was constructed with the given
/// Notifies this subscriber that a new span was constructed with the given
/// `Attributes` and `Id`.
fn new_span(
&self,
Expand Down
10 changes: 5 additions & 5 deletions tracing-flame/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ thread_local! {
/// samples.
///
/// The output of `FlameSubscriber` emulates the output of commands like `perf` once
/// they've been collapsed by `inferno-flamegraph`. The output of this layer
/// they've been collapsed by `inferno-flamegraph`. The output of this subscriber
/// should look similar to the output of the following commands:
///
/// ```sh
Expand Down Expand Up @@ -266,7 +266,7 @@ where
/// provided writer.
pub fn new(writer: W) -> Self {
// Initialize the start used by all threads when initializing the
// LAST_EVENT when constructing the layer
// LAST_EVENT when constructing the subscriber
let _unused = *START;
Self {
out: Arc::new(Mutex::new(writer)),
Expand Down Expand Up @@ -378,9 +378,9 @@ where
})
.map_err(Error)?;
let writer = BufWriter::new(file);
let layer = Self::new(writer);
let guard = layer.flush_on_drop();
Ok((layer, guard))
let subscriber = Self::new(writer);
let guard = subscriber.flush_on_drop();
Ok((subscriber, guard))
}
}

Expand Down
2 changes: 1 addition & 1 deletion tracing-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
//!
//! If the logging of trace events generated from log records produced by the
//! `log` crate is desired, either the `log` crate should not be used to
//! implement this logging, or an additional layer of filtering will be
//! implement this logging, or an additional subscriber of filtering will be
//! required to avoid infinitely converting between `Event` and `log::Record`.
//!
//! # Feature Flags
Expand Down
36 changes: 18 additions & 18 deletions tracing-subscriber/src/fmt/fmt_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ use tracing_core::{
/// use tracing_subscriber::prelude::*;
///
/// let fmt = format().with_timer(time::Uptime::default());
/// let fmt_layer = fmt::subscriber()
/// let fmt_subscriber = fmt::subscriber()
/// .event_format(fmt)
/// .with_target(false);
/// # let subscriber = fmt_layer.with_collector(tracing_subscriber::registry::Registry::default());
/// # let subscriber = fmt_subscriber.with_collector(tracing_subscriber::registry::Registry::default());
/// # tracing::collect::set_global_default(subscriber).unwrap();
/// ```
///
Expand All @@ -76,14 +76,14 @@ impl<S> Subscriber<S> {
}
}

// This needs to be a seperate impl block because they place different bounds on the type parameters.
// This needs to be a separate impl block because they place different bounds on the type parameters.
impl<S, N, E, W> Subscriber<S, N, E, W>
where
S: Collect + for<'a> LookupSpan<'a>,
N: for<'writer> FormatFields<'writer> + 'static,
W: for<'writer> MakeWriter<'writer> + 'static,
{
/// Sets the [event formatter][`FormatEvent`] that the layer will use to
/// Sets the [event formatter][`FormatEvent`] that the subscriber will use to
/// format events.
///
/// The event formatter may be any type implementing the [`FormatEvent`]
Expand All @@ -96,11 +96,11 @@ where
/// ```rust
/// use tracing_subscriber::fmt::{self, format};
///
/// let layer = fmt::subscriber()
/// let fmt_subscriber = fmt::subscriber()
/// .event_format(format().compact());
/// # // this is necessary for type inference.
/// # use tracing_subscriber::Subscribe as _;
/// # let _ = layer.with_collector(tracing_subscriber::registry::Registry::default());
/// # let _ = fmt_subscriber.with_collector(tracing_subscriber::registry::Registry::default());
/// ```
/// [`FormatEvent`]: format::FormatEvent
/// [`Event`]: tracing::Event
Expand All @@ -118,7 +118,7 @@ where
}
}

// This needs to be a seperate impl block because they place different bounds on the type parameters.
// This needs to be a separate impl block because they place different bounds on the type parameters.
impl<S, N, E, W> Subscriber<S, N, E, W> {
/// Sets the [`MakeWriter`] that the [`Subscriber`] being built will use to write events.
///
Expand All @@ -130,11 +130,11 @@ impl<S, N, E, W> Subscriber<S, N, E, W> {
/// use std::io;
/// use tracing_subscriber::fmt;
///
/// let layer = fmt::subscriber()
/// let fmt_subscriber = fmt::subscriber()
/// .with_writer(io::stderr);
/// # // this is necessary for type inference.
/// # use tracing_subscriber::Subscribe as _;
/// # let _ = layer.with_collector(tracing_subscriber::registry::Registry::default());
/// # let _ = fmt_subscriber.with_collector(tracing_subscriber::registry::Registry::default());
/// ```
///
/// [`MakeWriter`]: super::writer::MakeWriter
Expand Down Expand Up @@ -165,11 +165,11 @@ impl<S, N, E, W> Subscriber<S, N, E, W> {
/// use std::io;
/// use tracing_subscriber::fmt;
///
/// let layer = fmt::subscriber()
/// let fmt_subscriber = fmt::subscriber()
/// .with_test_writer();
/// # // this is necessary for type inference.
/// # use tracing_subscriber::Subscribe as _;
/// # let _ = layer.with_collector(tracing_subscriber::registry::Registry::default());
/// # let _ = fmt_subscriber.with_collector(tracing_subscriber::registry::Registry::default());
/// ```
/// [capturing]:
/// https://doc.rust-lang.org/book/ch11-02-running-tests.html#showing-function-output
Expand Down Expand Up @@ -384,7 +384,7 @@ where
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
impl<S, T, W> Subscriber<S, format::JsonFields, format::Format<format::Json, T>, W> {
/// Sets the JSON layer being built to flatten event metadata.
/// Sets the JSON subscriber being built to flatten event metadata.
///
/// See [`format::Json`]
pub fn flatten_event(
Expand Down Expand Up @@ -436,7 +436,7 @@ impl<S, T, W> Subscriber<S, format::JsonFields, format::Format<format::Json, T>,
}

impl<S, N, E, W> Subscriber<S, N, E, W> {
/// Sets the field formatter that the layer being built will use to record
/// Sets the field formatter that the subscriber being built will use to record
/// fields.
pub fn fmt_fields<N2>(self, fmt_fields: N2) -> Subscriber<S, N2, E, W>
where
Expand Down Expand Up @@ -527,7 +527,7 @@ impl<E> Deref for FormattedFields<E> {
}
}

// === impl FmtLayer ===
// === impl FmtSubscriber ===

macro_rules! with_event_from_span {
($id:ident, $span:ident, $($field:literal = $value:expr),*, |$event:ident| $code:block) => {
Expand Down Expand Up @@ -710,9 +710,9 @@ where
}

unsafe fn downcast_raw(&self, id: TypeId) -> Option<NonNull<()>> {
// This `downcast_raw` impl allows downcasting a `fmt` layer to any of
// This `downcast_raw` impl allows downcasting a `fmt` subscriber to any of
// its components (event formatter, field formatter, and `MakeWriter`)
// as well as to the layer's type itself. The potential use-cases for
// as well as to the subscriber's type itself. The potential use-cases for
// this *may* be somewhat niche, though...
match () {
_ if id == TypeId::of::<Self>() => Some(NonNull::from(self).cast()),
Expand Down Expand Up @@ -894,7 +894,7 @@ mod test {
}

#[test]
fn fmt_layer_downcasts() {
fn fmt_subscriber_downcasts() {
let f = format::Format::default();
let fmt = fmt::Subscriber::default().event_format(f);
let subscriber = fmt.with_collector(Registry::default());
Expand All @@ -906,7 +906,7 @@ mod test {
}

#[test]
fn fmt_layer_downcasts_to_parts() {
fn fmt_subscriber_downcasts_to_parts() {
let f = format::Format::default();
let fmt = fmt::Subscriber::default().event_format(f);
let subscriber = fmt.with_collector(Registry::default());
Expand Down
9 changes: 6 additions & 3 deletions tracing-subscriber/src/fmt/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ use fmt::{Debug, Display};

/// A type that can format a tracing `Event` for a `fmt::Write`.
///
/// `FormatEvent` is primarily used in the context of [`fmt::Collector`] or [`fmt::Subscriber`]. Each time an event is
/// dispatched to [`fmt::Collector`] or [`fmt::Subscriber`], the subscriber or layer forwards it to
/// its associated `FormatEvent` to emit a log message.
/// `FormatEvent` is primarily used in the context of [`fmt::Collector`] or [`fmt::Subscriber`].
/// Each time an event is dispatched to [`fmt::Collector`] or [`fmt::Subscriber`],
/// the collector or subscriber forwards it to its associated `FormatEvent` to emit a log message.
///
/// This trait is already implemented for function pointers with the same
/// signature as `format_event`.
Expand Down Expand Up @@ -191,11 +191,14 @@ pub trait FormatFields<'writer> {
/// .event_format(format)
/// .init();
/// ```
/// [event formatter]: FormatEvent
pub fn format() -> Format {
Format::default()
}

/// Returns the default configuration for a JSON [event formatter].
///
/// [event formatter]: FormatEvent
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
pub fn json() -> Format<Json> {
Expand Down
2 changes: 1 addition & 1 deletion tracing-subscriber/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ pub use self::{

/// A `Collector` that logs formatted representations of `tracing` events.
///
/// This consists of an inner `Formatter` wrapped in a layer that performs filtering.
/// This consists of an inner `Formatter` wrapped in a subscriber that performs filtering.
#[derive(Debug)]
pub struct Collector<
N = format::DefaultFields,
Expand Down
4 changes: 2 additions & 2 deletions tracing-subscriber/src/fmt/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{
/// This trait is already implemented for function pointers and
/// immutably-borrowing closures that return an instance of [`io::Write`], such
/// as [`io::stdout`] and [`io::stderr`]. Additionally, it is implemented for
/// [`std::sync::Mutex`][mutex] when the tyoe inside the mutex implements
/// [`std::sync::Mutex`][mutex] when the type inside the mutex implements
/// [`io::Write`].
///
/// # Examples
Expand Down Expand Up @@ -112,7 +112,7 @@ pub trait MakeWriter<'a> {
fn make_writer(&'a self) -> Self::Writer;
}

/// A type implementing [`io::Write`] for a [`MutexGuard`] where tyhe type
/// A type implementing [`io::Write`] for a [`MutexGuard`] where the type
/// inside the [`Mutex`] implements [`io::Write`].
///
/// This is used by the [`MakeWriter`] implementation for [`Mutex`], because
Expand Down
2 changes: 1 addition & 1 deletion tracing-subscriber/src/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub struct Parents<'a, R> {
/// An iterator over a span's parents, starting with the root of the trace
/// tree.
///
/// For additonal details, see [`SpanRef::from_root`].
/// For additional details, see [`SpanRef::from_root`].
///
/// [`Span::from_root`]: SpanRef::from_root()
pub struct FromRoot<'a, R: LookupSpan<'a>> {
Expand Down
6 changes: 1 addition & 5 deletions tracing-subscriber/src/registry/sharded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,7 @@ impl Collect for Registry {
// calls to `try_close`: we have to ensure that all threads have
// dropped their refs to the span before the span is closed.
let refs = span.ref_count.fetch_add(1, Ordering::Relaxed);
assert!(
refs != 0,
"tried to clone a span ({:?}) that already closed",
id
);
assert_ne!(refs, 0, "tried to clone a span ({:?}) that already closed", id);
id.clone()
}

Expand Down
Loading

0 comments on commit fe59f77

Please sign in to comment.