#progress-bar #logging #progress #log-line #log

indicatif-log-bridge

Bridge the log crate and indicatif to stop log lines from mixing up with progress bars

5 releases

0.2.3 Aug 24, 2024
0.2.2 Aug 31, 2023
0.2.1 Jul 31, 2023
0.2.0 Jul 31, 2023
0.1.0 Jul 31, 2023

#92 in Concurrency

Download history 8473/week @ 2024-08-19 8672/week @ 2024-08-26 7363/week @ 2024-09-02 12404/week @ 2024-09-09 9293/week @ 2024-09-16 9997/week @ 2024-09-23 8476/week @ 2024-09-30 8634/week @ 2024-10-07 7391/week @ 2024-10-14 6983/week @ 2024-10-21 6113/week @ 2024-10-28 9037/week @ 2024-11-04 7730/week @ 2024-11-11 6187/week @ 2024-11-18 5318/week @ 2024-11-25 6368/week @ 2024-12-02

26,069 downloads per month
Used in 33 crates (24 directly)

MIT license

8KB

Indicatif Log Bridge

Tired of your log lines and progress bars mixing up? indicatif_log_bridge to the rescue!

Simply wrap your favourite logging implementation in [LogWrapper] and those worries are a thing of the past.

Just remember add each ProgressBar to the [MultiProgress] you used , otherwise you are back to ghostly halves of progress bars everywhere.

Example

    let logger =
        env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
            .build();
    let level = logger.filter();
    let multi = MultiProgress::new();

    LogWrapper::new(multi.clone(), logger)
        .try_init()
        .unwrap();
    log::set_max_level(level);

    let pg = multi.add(ProgressBar::new(10));
    for i in (0..10) {
        std::thread::sleep(Duration::from_micros(100));
        info!("iteration {}", i);
        pg.inc(1);
    }
    pg.finish();
    multi.remove(&pg);

The code of this crate is pretty simple, so feel free to check it out.

Known Issues

Wrong Global Log Level

The log framework has a global minimum level, set using log::set_max_level. If that is set to Debug, the trace! macro will not fire at all. The [Log] trait does not provide a standartized way of querying the expected level. LogWrapper::try_init tries hard to find the correct level, but does not always get it right, especially if different levels are specified for different modules or crates, as is often the case with the env_logger crate.

Workaround

For env_logger specifically you can use logger.filter() to query the level before constructing and initializing the [LogWrapper] and then passit to log::set_max_level afterwards. If you copy the example code you should be fine.

Dependencies

~3–9.5MB
~92K SLoC