pub trait StatsLogger: Send {
// Required methods
fn group_start(&mut self);
fn group_log(&mut self, id: Id, value: LogValue) -> Result<(), LogError>;
fn group_end(&mut self);
fn flush(&mut self);
// Provided methods
fn log(&mut self, id: Id, value: LogValue) -> Result<(), LogError> { ... }
fn group(self) -> LogGroup<Self>
where Self: Sized { ... }
fn with_scope(self, scope: &'static str) -> ScopedLogger<Self>
where Self: Sized { ... }
fn log_counter_increment(&mut self, name: &'static str, increment: u64) { ... }
fn log_duration(&mut self, name: &'static str, duration: Duration) { ... }
fn log_elapsed<F, T>(&mut self, name: &'static str, f: F) -> T
where F: FnOnce(&mut Self) -> T,
Self: Sized { ... }
fn log_scalar(&mut self, name: &'static str, value: f64) { ... }
fn log_index(&mut self, name: &'static str, value: usize, size: usize) { ... }
}
Expand description
Log a time series of statistics.
Statistics with the same name may be aggregated or summarized over some time period.
Required Methods§
Sourcefn group_start(&mut self)
fn group_start(&mut self)
Internal helper. Do not call directly. Handle the creation of a LogGroup
. May flush.
Sourcefn group_log(&mut self, id: Id, value: LogValue) -> Result<(), LogError>
fn group_log(&mut self, id: Id, value: LogValue) -> Result<(), LogError>
Internal helper. Do not call directly. Log a value within a LogGroup
. May not flush.
Provided Methods§
Sourcefn log(&mut self, id: Id, value: LogValue) -> Result<(), LogError>
fn log(&mut self, id: Id, value: LogValue) -> Result<(), LogError>
Log a value associated with an ID.
§Args
-
id
- Unique identifier of the statistic to log. Used to track the value over time. It is an error to use the same identifier with values that have differentLogValue
variants or are otherwise structurally incompatible.The ID can be created from a string with
into()
. It is a hierarchical name, similar to a file system path. Logger scope names (created withStatsLogger::with_scope
) will be prepended to the given ID. -
value
- The value to log.
Sourcefn group(self) -> LogGroup<Self>where
Self: Sized,
fn group(self) -> LogGroup<Self>where
Self: Sized,
Create a logger for a group of related values.
Once the group has been created, no flushing will occur until the group is dropped.
This can be called on a reference for a temporary group: (&mut logger).group()
Sourcefn with_scope(self, scope: &'static str) -> ScopedLogger<Self>where
Self: Sized,
fn with_scope(self, scope: &'static str) -> ScopedLogger<Self>where
Self: Sized,
Wrap this logger such that an inner scope is added to all logged ids.
This can be called on a reference for a temporary scope: (&mut logger).with_scope(...)
Sourcefn log_counter_increment(&mut self, name: &'static str, increment: u64)
fn log_counter_increment(&mut self, name: &'static str, increment: u64)
Log an increment to a named counter (convenience function).
Panics if this name was previously used to log a value of a different type.
Sourcefn log_duration(&mut self, name: &'static str, duration: Duration)
fn log_duration(&mut self, name: &'static str, duration: Duration)
Log a named duration (convenience function).
Panics if this name was previously used to log a value of a different type.
Sourcefn log_elapsed<F, T>(&mut self, name: &'static str, f: F) -> T
fn log_elapsed<F, T>(&mut self, name: &'static str, f: F) -> T
Log a named duration as the elapsed time in evaluating a closure.
The closure is passed a mutable reference to this logger so that it has the opportunity to make its own logging calls.
Sourcefn log_scalar(&mut self, name: &'static str, value: f64)
fn log_scalar(&mut self, name: &'static str, value: f64)
Log a named scalar value (convenience function).
Panics if this name was previously used to log a value of a different type.
Implementations on Foreign Types§
Source§impl StatsLogger for ()
No-op logger
impl StatsLogger for ()
No-op logger
Source§impl<A, B> StatsLogger for (A, B)where
A: StatsLogger,
B: StatsLogger,
Pair of loggers; logs to both.
impl<A, B> StatsLogger for (A, B)where
A: StatsLogger,
B: StatsLogger,
Pair of loggers; logs to both.