🛈 Note: This is pre-release documentation for the upcoming tracing 0.2.0 ecosystem.

For the release documentation, please see docs.rs, instead.

tracing_subscriber::fmt

Struct FmtContext

Source
pub struct FmtContext<'a, C, N> { /* private fields */ }
Available on crate features fmt and std only.
Expand description

Provides the current span context to a formatter.

Implementations§

Source§

impl<'a, C, N> FmtContext<'a, C, N>
where C: Collect + for<'lookup> LookupSpan<'lookup>, N: for<'writer> FormatFields<'writer> + 'static,

Source

pub fn visit_spans<E, F>(&self, f: F) -> Result<(), E>
where F: FnMut(&SpanRef<'_, C>) -> Result<(), E>,

Visits every span in the current context with a closure.

The provided closure will be called first with the current span, and then with that span’s parent, and then that span’s parent, and so on until a root span is reached.

Source

pub fn metadata(&self, id: &Id) -> Option<&'static Metadata<'static>>
where C: for<'lookup> LookupSpan<'lookup>,

Returns metadata for the span with the given id, if it exists.

If this returns None, then no span exists for that ID (either it has closed or the ID is invalid).

Source

pub fn span(&self, id: &Id) -> Option<SpanRef<'_, C>>
where C: for<'lookup> LookupSpan<'lookup>,

Returns stored data for the span with the given id, if it exists.

If this returns None, then no span exists for that ID (either it has closed or the ID is invalid).

Source

pub fn exists(&self, id: &Id) -> bool
where C: for<'lookup> LookupSpan<'lookup>,

Returns true if an active span exists for the given Id.

Source

pub fn lookup_current(&self) -> Option<SpanRef<'_, C>>
where C: for<'lookup> LookupSpan<'lookup>,

Returns stored data for the span that the wrapped subscriber considers to be the current.

If this returns None, then we are not currently within a span.

Source

pub fn current_span(&self) -> Current

Returns the current span for this formatter.

Source

pub fn parent_span(&self) -> Option<SpanRef<'_, C>>

Returns stored data for the parent span of the event currently being formatted.

If the event has a contextual parent, this will return the current span. If the event has an explicit parent span, this will return that span. If the event does not have a parent span, this will return None.

Source

pub fn span_scope(&self, id: &Id) -> Option<Scope<'_, C>>
where C: for<'lookup> LookupSpan<'lookup>,

Returns an iterator over the stored data for all the spans in the current context, starting with the specified span and ending with the root of the trace tree and ending with the current span.

This is equivalent to the Context::span_scope method.

Note
Note: Compared to scope this
returns the spans in reverse order (from leaf to root). Use
Scope::from_root
in case root-to-leaf ordering is desired.
Note: This requires the wrapped subscriber to implement the
LookupSpan trait.
See the documentation on Context's
declaration for details.
Source

pub fn event_scope(&self) -> Option<Scope<'_, C>>
where C: for<'lookup> LookupSpan<'lookup>,

Returns an iterator over the stored data for all the spans in the event’s span context, starting with its parent span and ending with the root of the trace tree.

This is equivalent to calling the Context::event_scope method and passing the event currently being formatted.

Note: Compared to scope this
returns the spans in reverse order (from leaf to root). Use
Scope::from_root
in case root-to-leaf ordering is desired.
Note: This requires the wrapped subscriber to implement the
LookupSpan trait.
See the documentation on Context's
declaration for details.
Source

pub fn field_format(&self) -> &N

Returns the field formatter configured by the subscriber invoking format_event.

The event formatter may use the returned field formatter to format the fields of any events it records.

Trait Implementations§

Source§

impl<'a, C, N> Debug for FmtContext<'a, C, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'cx, 'writer, C, N> FormatFields<'writer> for FmtContext<'cx, C, N>
where C: Collect + for<'lookup> LookupSpan<'lookup>, N: FormatFields<'writer> + 'static,

Source§

fn format_fields<R: RecordFields>( &self, writer: Writer<'writer>, fields: R, ) -> Result

Format the provided fields to the provided Writer, returning a result.
Source§

fn add_fields( &self, current: &'writer mut FormattedFields<Self>, fields: &Record<'_>, ) -> Result

Record additional field(s) on an existing span. Read more

Auto Trait Implementations§

§

impl<'a, C, N> Freeze for FmtContext<'a, C, N>

§

impl<'a, C, N> !RefUnwindSafe for FmtContext<'a, C, N>

§

impl<'a, C, N> !Send for FmtContext<'a, C, N>

§

impl<'a, C, N> !Sync for FmtContext<'a, C, N>

§

impl<'a, C, N> Unpin for FmtContext<'a, C, N>

§

impl<'a, C, N> !UnwindSafe for FmtContext<'a, C, N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithCollector for T

Source§

fn with_collector<C>(self, collector: C) -> WithDispatch<Self>
where C: Into<Dispatch>,

Attaches the provided collector to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_collector(self) -> WithDispatch<Self>

Attaches the current default collector to this type, returning a WithDispatch wrapper. Read more