Skip to main content

ProgressLogger

Struct ProgressLogger 

Source
pub struct ProgressLogger { /* private fields */ }
Expand description

An implementation of ProgressLog with output generated using the log crate at a configurable level (default: info).

Instances can be created by using fluent setters, or by using the progress_logger macro.

You can clone a logger to create a new one with the same setup but with all the counters reset and the expected number of updates cleared. This behavior is useful when you want to configure a logger and then use its configuration for other loggers.

§Examples

A typical call sequence to a progress logger is as follows:

env_logger::builder().filter_level(log::LevelFilter::Info).try_init()?;

let mut pl = ProgressLogger::default();
pl.item_name("pumpkin");
pl.start("Smashing pumpkins...");
for _ in 0..100 {
   // do something on each pumpkin
   pl.update();
}
pl.done();

The progress_logger macro will create the progress logger for you and set its log_target to std::module_path!(), which is usually what you want. You can also call any setter with a key-value syntax:

env_logger::builder().filter_level(log::LevelFilter::Info).try_init()?;

let mut pl = progress_logger![item_name="pumpkin"];
pl.start("Smashing pumpkins...");
for _ in 0..100 {
   // do something on each pumpkin
   pl.update();
}
pl.done();

A progress logger can also be used as a handy timer:

env_logger::builder().filter_level(log::LevelFilter::Info).try_init()?;

let mut pl = progress_logger![item_name="pumpkin"];
pl.start("Smashing pumpkins...");
for _ in 0..100 {
   // do something on each pumpkin
}
pl.done_with_count(100);

This progress logger will display information about memory usage:

env_logger::builder().filter_level(log::LevelFilter::Info).try_init()?;

let mut pl = progress_logger![display_memory=true];

Implementations§

Source§

impl ProgressLogger

Source

pub const LIGHT_UPDATE_MASK: usize

Calls to light_update will cause a call to Instant::now only if the current count is a multiple of this mask plus one.

Trait Implementations§

Source§

impl Clone for ProgressLogger

Source§

fn clone(&self) -> Self

Clones the logger, returning a logger with the same setup but with all the counters reset and the expected number of updates cleared.

The expected number of updates is cleared, as in stop, because it rarely carries over to another activity; if needed, it can be set again with expected_updates. Note that this behavior extends to ProgressLog::concurrent and ConcurrentProgressLog::dup, which clone the underlying logger.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for ProgressLogger

Source§

fn default() -> Self

Creates a default ProgressLogger with a log interval of 10 seconds and item name set to “item”.

Source§

impl Display for ProgressLogger

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ProgressLog for ProgressLogger

Source§

fn light_update(&mut self)

Increases the count and, once every LIGHT_UPDATE_MASK + 1 calls, checks whether it is time to log.

Source§

type Concurrent = ConcurrentWrapper

The type returned by concurrent.
Source§

fn log(&mut self, now: Instant)

Forces a log of self assuming now is the current time. Read more
Source§

fn log_if(&mut self, now: Instant)

Logs self if it is time to log. Read more
Source§

fn add_to_count(&mut self, count: usize)

Adds a value to the counter. Read more
Source§

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

Sets the display of memory information. Read more
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: impl Into<Option<usize>>, ) -> &mut Self

Sets the expected number of updates. Read more
Source§

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

Sets the time unit to use for speed. Read more
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 log_target(&mut self, target: impl AsRef<str>) -> &mut Self

Sets the log target. Read more
Source§

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

Pushes a suffix to the log target. Read more
Source§

fn pop_log_target(&mut self) -> &mut Self

Pops the last suffix pushed with push_log_target. Read more
Source§

fn log_level(&mut self, log_level: Level) -> &mut Self

Sets the log level used for progress messages. Read more
Source§

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

Starts the logger, displaying the given message. Read more
Source§

fn refresh(&mut self)

Refreshes memory information, if previously requested with display_memory. There is no need to call this method unless the logger is displayed manually.
Source§

fn update(&mut self)

Increases the count and checks whether it is time to log.
Source§

fn update_with_count_and_time(&mut self, count: usize, now: Instant)

Sets the count and checks whether it is time to log, given the current time. Read more
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, prints Completed., and displays 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. Read more
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 count(&self) -> usize

Returns the last count the logger has been set to. Read more
Source§

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

Outputs the given message at the trace level. Read more
Source§

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

Outputs the given message at the debug level. Read more
Source§

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

Outputs the given message at the info level. Read more
Source§

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

Outputs the given message at the warn level. Read more
Source§

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

Outputs the given message at the error level. Read more
Source§

fn concurrent(&self) -> Self::Concurrent

Returns a concurrent copy of the logger. Read more
Source§

fn update_with_count(&mut self, count: usize)

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.