pub trait ProgressLog {
Show 19 methods // Required methods fn display_memory(&mut self, display_memory: bool) -> &mut Self; fn item_name(&mut self, item_name: impl AsRef<str>) -> &mut Self; fn log_interval(&mut self, log_interval: Duration) -> &mut Self; fn expected_updates(&mut self, expected_updates: Option<usize>) -> &mut Self; fn time_unit(&mut self, time_unit: Option<TimeUnit>) -> &mut Self; fn local_speed(&mut self, local_speed: bool) -> &mut Self; fn log_target(&mut self, target: impl AsRef<str>) -> &mut Self; fn start(&mut self, msg: impl AsRef<str>); fn update(&mut self); fn update_with_count(&mut self, count: usize); fn light_update(&mut self); fn update_and_display(&mut self); fn stop(&mut self); fn done(&mut self); fn done_with_count(&mut self, count: usize); fn elapsed(&self) -> Option<Duration>; fn refresh(&mut self); fn info(&self, args: Arguments<'_>); fn clone(&self) -> Self;
}
Expand description

Logging trait.

Implemented by ProgressLog and by Option<ProgressLog>. This approach makes it possible to pass as a ProgressLog either a ProgressLogger, an Option<ProgressLogger>, or even Option::<ProgressLogger>::None.

Required Methods§

source

fn display_memory(&mut self, display_memory: bool) -> &mut Self

Sets the display of memory information.

Memory information include:

source

fn item_name(&mut self, item_name: impl AsRef<str>) -> &mut Self

Sets the name of an item.

source

fn log_interval(&mut self, log_interval: Duration) -> &mut Self

Sets the log interval.

source

fn expected_updates(&mut self, expected_updates: Option<usize>) -> &mut Self

Sets the expected number of updates.

If not None, the logger will display the percentage of completion and an estimate of the time to completion.

source

fn time_unit(&mut self, time_unit: Option<TimeUnit>) -> &mut Self

Sets the time unit to use for speed.

If not None, the logger will always display the speed in this unit instead of making a choice of readable unit based on the elapsed time. Moreover, large numbers will not be thousands separated. This behavior is useful when the output of the logger must be parsed.

source

fn local_speed(&mut self, local_speed: bool) -> &mut Self

Set whether to display additionally the speed achieved during the last log interval.

source

fn log_target(&mut self, target: impl AsRef<str>) -> &mut Self

Sets the log target.

This should often be the path of the module logging progress, which is obtained with std::module_path!.

Note that the macro progress_logger! sets this field automatically to std::module_path!.

§Examples
use dsi_progress_logger::prelude::*;

stderrlog::new().verbosity(2).init()?;

let mut pl = ProgressLogger::default();
pl.item_name("pumpkin");
pl.log_target(std::module_path!());
pl.start("Smashing pumpkins from a module...");
for _ in 0..100 {
   // do something on each pumpkin
   pl.update();
}
pl.done();
source

fn start(&mut self, msg: impl AsRef<str>)

Starts the logger, displaying the given message.

You can pass the empty string to display nothing.

source

fn update(&mut self)

Increases the count and check whether it is time to log.

source

fn update_with_count(&mut self, count: usize)

Sets the count and check whether it is time to log.

source

fn light_update(&mut self)

Increases the count but checks whether it is time log only after an implementation-defined number of calls.

Useful for very short activities with respect to which checking the time is expensive.

source

fn update_and_display(&mut self)

Increases the count and forces a log.

source

fn stop(&mut self)

Stops the logger, fixing the final time.

source

fn done(&mut self)

Stops the logger, print Completed., and display the final stats. The number of expected updates will be cleared.

source

fn done_with_count(&mut self, count: usize)

Stops the logger, sets the count, prints Completed., and displays the final stats. The number of expected updates will be cleared.

This method is particularly useful in two circumstances:

  • you have updated the logger with some approximate values (e.g., in a multicore computation) but before printing the final stats you want the internal counter to contain an exact value;
  • you have used the logger as a handy timer, calling just start and this method.
source

fn elapsed(&self) -> Option<Duration>

Returns the elapsed time since the logger was started, or None if the logger has not been started.

source

fn refresh(&mut self)

Refreshes memory information, if previously requested with display_memory. You do not need to call this method unless you display the logger manually.

source

fn info(&self, args: Arguments<'_>)

Outputs the given message.

For maximum flexibility, this method takes as argument the result of a std::format_args! macro. Note that there will be no output if the logger is the None variant.

§Examples
use dsi_progress_logger::*;

stderrlog::new().verbosity(2).init()?;

let logger_name = "my_logger";
let mut pl = progress_logger!();
pl.info(format_args!("My logger named {}", logger_name));
source

fn clone(&self) -> Self

Clones the logger, returning a logger with the same setup but with all the counters reset.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<P: ProgressLog> ProgressLog for Option<P>

source§

fn local_speed(&mut self, local_speed: bool) -> &mut Self

Sets whether to display additionally the speed achieved during the last log interval.

source§

fn display_memory(&mut self, display_memory: bool) -> &mut Self

source§

fn item_name(&mut self, item_name: impl AsRef<str>) -> &mut Self

source§

fn log_interval(&mut self, log_interval: Duration) -> &mut Self

source§

fn expected_updates(&mut self, expected_updates: Option<usize>) -> &mut Self

source§

fn time_unit(&mut self, time_unit: Option<TimeUnit>) -> &mut Self

source§

fn log_target(&mut self, target: impl AsRef<str>) -> &mut Self

source§

fn start(&mut self, msg: impl AsRef<str>)

source§

fn update(&mut self)

source§

fn update_with_count(&mut self, count: usize)

source§

fn light_update(&mut self)

source§

fn update_and_display(&mut self)

source§

fn stop(&mut self)

source§

fn done(&mut self)

source§

fn done_with_count(&mut self, count: usize)

source§

fn elapsed(&self) -> Option<Duration>

source§

fn refresh(&mut self)

source§

fn info(&self, args: Arguments<'_>)

source§

fn clone(&self) -> Self

Implementors§