Trait StatsLogger

Source
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§

Source

fn group_start(&mut self)

Internal helper. Do not call directly. Handle the creation of a LogGroup. May flush.

Source

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.

Source

fn group_end(&mut self)

Internal helper. Do not call directly. Handle the drop of a LogGroup. May flush.

Source

fn flush(&mut self)

Record any remaining data in the logger that has not yet been recorded.

Provided Methods§

Source

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 different LogValue 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 with StatsLogger::with_scope) will be prepended to the given ID.

  • value - The value to log.

Source

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()

Source

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(...)

Source

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.

Source

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.

Source

fn log_elapsed<F, T>(&mut self, name: &'static str, f: F) -> T
where F: FnOnce(&mut Self) -> T, Self: Sized,

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.

Source

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.

Source

fn log_index(&mut self, name: &'static str, value: usize, size: usize)

Log a named index in 0 to size - 1 (convenience function).

Panics if this name was previously used to log a value of a different type or an index value with a different size.

Implementations on Foreign Types§

Source§

impl StatsLogger for ()

No-op logger

Source§

fn group_start(&mut self)

Source§

fn group_log(&mut self, _: Id, _: LogValue) -> Result<(), LogError>

Source§

fn group_end(&mut self)

Source§

fn flush(&mut self)

Source§

impl<A, B> StatsLogger for (A, B)
where A: StatsLogger, B: StatsLogger,

Pair of loggers; logs to both.

Source§

fn group_start(&mut self)

Source§

fn group_log(&mut self, id: Id, value: LogValue) -> Result<(), LogError>

Source§

fn group_end(&mut self)

Source§

fn flush(&mut self)

Source§

impl<T> StatsLogger for &mut T
where T: StatsLogger + ?Sized,

Source§

fn group_start(&mut self)

Source§

fn group_log(&mut self, id: Id, value: LogValue) -> Result<(), LogError>

Source§

fn group_end(&mut self)

Source§

fn flush(&mut self)

Source§

impl<T> StatsLogger for Box<T>
where T: StatsLogger + ?Sized,

Source§

fn group_start(&mut self)

Source§

fn group_log(&mut self, id: Id, value: LogValue) -> Result<(), LogError>

Source§

fn group_end(&mut self)

Source§

fn flush(&mut self)

Implementors§

Source§

impl<C: Chunker> StatsLogger for DisplayLogger<C>

Source§

impl<C: Chunker> StatsLogger for TensorBoardLogger<C>

Source§

impl<C: Chunker, W: SummaryWriter> StatsLogger for ChunkLogger<C, W>

Source§

impl<L: StatsLogger> StatsLogger for LogGroup<L>

Source§

impl<L: StatsLogger> StatsLogger for ScopedLogger<L>