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
impl ProgressLogger
Sourcepub const LIGHT_UPDATE_MASK: usize
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
impl Clone for ProgressLogger
Source§fn clone(&self) -> Self
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)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for ProgressLogger
impl Default for ProgressLogger
Source§fn default() -> Self
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
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,
checks 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: impl Into<Option<usize>>,
) -> &mut Self
fn expected_updates( &mut self, expected_updates: impl Into<Option<usize>>, ) -> &mut Self
Source§fn time_unit(&mut self, time_unit: impl Into<Option<TimeUnit>>) -> &mut Self
fn time_unit(&mut self, time_unit: impl Into<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 push_log_target(&mut self, suffix: impl AsRef<str>) -> &mut Self
fn push_log_target(&mut self, suffix: impl AsRef<str>) -> &mut Self
Source§fn pop_log_target(&mut self) -> &mut Self
fn pop_log_target(&mut self) -> &mut Self
push_log_target. Read moreSource§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. There is no need to
call this method unless the logger is displayed 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 displays 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.