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
impl ProgressLogger
Sourcepub const LIGHT_UPDATE_MASK: usize = 1_048_575usize
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
impl Clone for ProgressLogger
Source§impl Default for ProgressLogger
impl Default for ProgressLogger
Source§fn default() -> Self
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
impl Display for ProgressLogger
Source§impl ProgressLog for ProgressLogger
impl ProgressLog for ProgressLogger
Source§fn light_update(&mut self)
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
type Concurrent = ConcurrentWrapper
concurrent
.Source§fn add_to_count(&mut self, count: usize)
fn add_to_count(&mut self, count: usize)
Source§fn display_memory(&mut self, display_memory: bool) -> &mut Self
fn display_memory(&mut self, display_memory: bool) -> &mut Self
Source§fn log_interval(&mut self, log_interval: Duration) -> &mut Self
fn log_interval(&mut self, log_interval: Duration) -> &mut Self
Source§fn expected_updates(&mut self, expected_updates: Option<usize>) -> &mut Self
fn expected_updates(&mut self, expected_updates: Option<usize>) -> &mut Self
Source§fn time_unit(&mut self, time_unit: Option<TimeUnit>) -> &mut Self
fn time_unit(&mut self, time_unit: Option<TimeUnit>) -> &mut Self
Source§fn local_speed(&mut self, local_speed: bool) -> &mut Self
fn local_speed(&mut self, local_speed: bool) -> &mut Self
Source§fn start(&mut self, msg: impl AsRef<str>)
fn start(&mut self, msg: impl AsRef<str>)
Source§fn refresh(&mut self)
fn refresh(&mut self)
display_memory
. You do not need to call this
method unless you display the logger manually.Source§fn update_with_count_and_time(&mut self, count: usize, now: Instant)
fn update_with_count_and_time(&mut self, count: usize, now: Instant)
Source§fn update_and_display(&mut self)
fn update_and_display(&mut self)
Source§fn done(&mut self)
fn done(&mut self)
Completed.
, and display the final stats. The
number of expected updates will be cleared.Source§fn done_with_count(&mut self, count: usize)
fn done_with_count(&mut self, count: usize)
Completed.
, and displays the
final stats. The number of expected updates will be cleared. Read moreSource§fn elapsed(&self) -> Option<Duration>
fn elapsed(&self) -> Option<Duration>
None
if the
logger has not been started.Source§fn concurrent(&self) -> Self::Concurrent
fn concurrent(&self) -> Self::Concurrent
Source§fn update_with_count(&mut self, count: usize)
fn update_with_count(&mut self, count: usize)
Auto Trait Implementations§
impl Freeze for ProgressLogger
impl RefUnwindSafe for ProgressLogger
impl Send for ProgressLogger
impl Sync for ProgressLogger
impl Unpin for ProgressLogger
impl UnwindSafe for ProgressLogger
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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