Expand description
§mtlog-progress
A progress bar implementation working gracefully with mtlog’s logger.
§Usage with std threads
// Cargo.toml
...
[dependencies]
mtlog-progress = "0.2.0"
mtlog = "0.2.0"use mtlog::logger_config;
use mtlog_progress::LogProgressBar;
let _guard = logger_config()
.init_global();
let h = std::thread::spawn(|| {
let pb = LogProgressBar::new(100, "My Progress Bar");
for i in 0..100 {
pb.inc(1);
if i == 50 {
log::info!("Halfway there!");
}
}
pb.finish();
});
log::info!("This log goes below the progress bar");
h.join().unwrap(); // the progress bar continue to work at it's line position
// guard ensures logs are flushed when dropped§Usage with tokio tasks
§Usage
// Cargo.toml
...
[dependencies]
mtlog-progress = "0.1.0"
mtlog-tokio = "0.1.0"
tokio = { version = "1.40.0", features = ["full"] }use mtlog_tokio::logger_config;
use mtlog_progress::LogProgressBar;
#[tokio::main]
async fn main() {
logger_config()
.scope_global(async move {
let h = tokio::spawn(async move {
logger_config()
.scope_local(async move {
let pb = LogProgressBar::new(100, "My Progress Bar");
for i in 0..100 {
pb.inc(1);
if i == 50 {
log::info!("Halfway there!");
}
}
pb.finish();
}).await;
});
log::info!("This log goes below the progress bar");
h.await.unwrap(); // the progress bar continue to work at it's line position
}).await;
}§Iterator Progress Tracking
Use the .progress() method on iterators for automatic progress tracking:
use mtlog::logger_config;
use mtlog_progress::ProgressIteratorExt;
let _guard = logger_config().init_global();
// For ExactSizeIterator, automatically detects length
(0..100)
.progress("Processing")
.for_each(|i| {
// Work with i
});
// For any iterator, provide length manually
(0..=99)
.progress_with(100, "Processing")
.for_each(|_| {
// Work
});Structs§
- LogProgress
Bar - LogProgress
Iterator - A wrapper around an iterator that displays progress using
LogProgressBar. This struct is created by calling.progress()or.progress_with()on an iterator.
Traits§
- Progress
Iterator Ext - Extension trait for wrapping iterators with progress tracking.