#logging #multi-thread #progress

mtlog-progress

A progress bar implementation working gracefully with mtlog's logger

4 releases

new 0.1.3 Apr 18, 2025
0.1.2 Apr 9, 2025
0.1.1 Oct 23, 2024
0.1.0 Oct 16, 2024

#499 in Configuration

Download history 2/week @ 2025-02-19 4/week @ 2025-03-26 155/week @ 2025-04-09

159 downloads per month

MIT license

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.4–6.5MB
~39K SLoC