pub struct FmtContext<'a, C, N> { /* private fields */ }
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,
impl<'a, C, N> FmtContext<'a, C, N>where
C: Collect + for<'lookup> LookupSpan<'lookup>,
N: for<'writer> FormatFields<'writer> + 'static,
Sourcepub fn visit_spans<E, F>(&self, f: F) -> Result<(), E>
pub fn visit_spans<E, F>(&self, f: F) -> 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.
Sourcepub fn metadata(&self, id: &Id) -> Option<&'static Metadata<'static>> ⓘwhere
C: for<'lookup> LookupSpan<'lookup>,
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).
Sourcepub fn span(&self, id: &Id) -> Option<SpanRef<'_, C>> ⓘwhere
C: for<'lookup> LookupSpan<'lookup>,
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).
Sourcepub fn exists(&self, id: &Id) -> boolwhere
C: for<'lookup> LookupSpan<'lookup>,
pub fn exists(&self, id: &Id) -> boolwhere
C: for<'lookup> LookupSpan<'lookup>,
Returns true
if an active span exists for the given Id
.
Sourcepub fn lookup_current(&self) -> Option<SpanRef<'_, C>> ⓘwhere
C: for<'lookup> LookupSpan<'lookup>,
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.
Sourcepub fn current_span(&self) -> Current
pub fn current_span(&self) -> Current
Returns the current span for this formatter.
Sourcepub fn parent_span(&self) -> Option<SpanRef<'_, C>> ⓘ
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
.
Sourcepub fn span_scope(&self, id: &Id) -> Option<Scope<'_, C>> ⓘwhere
C: for<'lookup> LookupSpan<'lookup>,
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: Compared toscope
this returns the spans in reverse order (from leaf to root). UseScope::from_root
in case root-to-leaf ordering is desired.
Note: This requires the wrapped subscriber to implement theLookupSpan
trait. See the documentation onContext
's declaration for details.
Sourcepub fn event_scope(&self) -> Option<Scope<'_, C>> ⓘwhere
C: for<'lookup> LookupSpan<'lookup>,
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 toscope
this returns the spans in reverse order (from leaf to root). UseScope::from_root
in case root-to-leaf ordering is desired.
Note: This requires the wrapped subscriber to implement theLookupSpan
trait. See the documentation onContext
's declaration for details.
Sourcepub fn field_format(&self) -> &N
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>
impl<'a, C, N> Debug for FmtContext<'a, C, N>
Source§impl<'cx, 'writer, C, N> FormatFields<'writer> for FmtContext<'cx, C, N>
impl<'cx, 'writer, C, N> FormatFields<'writer> for FmtContext<'cx, C, N>
Source§fn format_fields<R: RecordFields>(
&self,
writer: Writer<'writer>,
fields: R,
) -> Result
fn format_fields<R: RecordFields>( &self, writer: Writer<'writer>, fields: R, ) -> Result
fields
to the provided Writer
, returning a result.