pub struct LogContext { /* private fields */ }Expand description
A log context saves informations about the current task, such as the elapsed time, the number of polls, and the poll time.
Implementations§
Source§impl LogContext
impl LogContext
Sourcepub fn new(tag: impl Into<Cow<'static, str>>) -> Self
pub fn new(tag: impl Into<Cow<'static, str>>) -> Self
Create a new log context with the given tag
Sourcepub fn maybe_with<F, R>(f: F) -> Option<R>where
F: FnOnce(&Self) -> R,
pub fn maybe_with<F, R>(f: F) -> Option<R>where
F: FnOnce(&Self) -> R,
Run a closure with the current log context, if any
Sourcepub fn run<F: FnOnce() -> Fut, Fut: Future>(
&self,
f: F,
) -> LogContextFuture<Fut>
pub fn run<F: FnOnce() -> Fut, Fut: Future>( &self, f: F, ) -> LogContextFuture<Fut>
Run the async function f with the given log context. It will wrap the
output future to record poll and CPU statistics.
Sourcepub fn run_sync<F: FnOnce() -> R, R>(&self, f: F) -> R
pub fn run_sync<F: FnOnce() -> R, R>(&self, f: F) -> R
Run the sync function f with the given log context, recording the CPU
time spent.
Sourcepub fn maybe_record_query_stats(fetched: usize, duration: Duration)
pub fn maybe_record_query_stats(fetched: usize, duration: Duration)
Record the stats of a query on the current log context.
Sourcepub fn record_query_stats(&self, fetched: usize, duration: Duration)
pub fn record_query_stats(&self, fetched: usize, duration: Duration)
Record the stats of a query
Sourcepub fn set_requester(&self, requester: Requester)
pub fn set_requester(&self, requester: Requester)
Associate a Requester with this log context. Silently does nothing
if a requester has already been recorded (first writer wins).
Sourcepub fn requester(&self) -> Option<&Requester>
pub fn requester(&self) -> Option<&Requester>
Get the Requester associated with this log context, if one was set.
Sourcepub fn maybe_set_requester(requester: Requester)
pub fn maybe_set_requester(requester: Requester)
Convenience: set the Requester on the current task-local
LogContext, if one exists. No-op outside of a LogContext scope.
Sourcepub fn stats(&self) -> LogContextStats
pub fn stats(&self) -> LogContextStats
Create a snapshot of the log context statistics
Trait Implementations§
Source§impl Clone for LogContext
impl Clone for LogContext
Source§fn clone(&self) -> LogContext
fn clone(&self) -> LogContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for LogContext
impl RefUnwindSafe for LogContext
impl Send for LogContext
impl Sync for LogContext
impl Unpin for LogContext
impl UnsafeUnpin for LogContext
impl UnwindSafe for LogContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.