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 more