Struct ProgressLogger

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

An implementation of ProgressLog with output generated using the log crate at the info level.

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. 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:

use dsi_progress_logger::prelude::*;

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:

use dsi_progress_logger::prelude::*;

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:

use dsi_progress_logger::prelude::*;

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:

use dsi_progress_logger::prelude::*;

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 = 1_048_575usize

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

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

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for ProgressLogger

Source§

fn default() -> Self

Create 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, check whether it is time to log.

Source§

type Concurrent = ConcurrentWrapper

The type returned by concurrent.
Source§

fn log(&mut self, now: Instant)

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

fn log_if(&mut self, now: Instant)

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

fn add_to_count(&mut self, count: usize)

Add a value to the counter. Read more
Source§

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

Set the display of memory information. Read more
Source§

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

Set the name of an item.
Source§

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

Set the log interval.
Source§

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

Set the expected number of updates. Read more
Source§

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

Set the time unit to use for speed. Read more
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

Set the log target. Read more
Source§

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

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

fn refresh(&mut self)

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

fn update(&mut self)

Increase the count and check whether it is time to log.
Source§

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

Set the count and check whether it is time to log, given the current time. Read more
Source§

fn update_and_display(&mut self)

Increase the count and forces a log.
Source§

fn stop(&mut self)

Stop the logger, fixing the final time.
Source§

fn done(&mut self)

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

Stop 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>

Return the elapsed time since the logger was started, or None if the logger has not been started.
Source§

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

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

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

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

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

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

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

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

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

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

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

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

fn update_with_count(&mut self, count: usize)

Set the count and check 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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.