2 releases
new 0.1.1 | Oct 23, 2024 |
---|---|
0.1.0 | Oct 16, 2024 |
#590 in Concurrency
229 downloads per month
7KB
80 lines
mtlog-progress
A progress bar implementation working gracefully with mtlog's logger.
Usage with std threads
// Cargo.toml
...
[dependencies]
mtlog-progress = "0.1.0"
mtlog = "0.1.4"
use mtlog::logger_config;
use mtlog_progress::LogProgressBar;
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
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;
}
Dependencies
~0.3–10MB
~48K SLoC