Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using indicatif and the log crate #566

Closed
djugei opened this issue Jul 29, 2023 · 1 comment
Closed

using indicatif and the log crate #566

djugei opened this issue Jul 29, 2023 · 1 comment

Comments

@djugei
Copy link
Contributor

djugei commented Jul 29, 2023

This is not an issue but instructions on how you can log messages and have a progress bar at the same time.
its an issue that comes up sometimes: #366 #92 #474 #27 possibly #474

You create a global MultiProgress, and then you just need to make your logging implementation, in this example env_logger use that (or rather its println function) as write target. to do so we utilize the pipe crate, but it would also be possible to use a ring buffer or something else:

let (read, write) = pipe::pipe();
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
    .target(env_logger::Target::Pipe(Box::new(write)))
    .init();

let multi = MultiProgress::new();

{
    let m = multi.clone();
    std::thread::spawn(move || {
        let br = std::io::BufReader::new(read);
        for line in br.lines() {
            let line = line.unwrap();
            m.println(&line);
        }
    });
}

then you simply add all your progress bars to the gobal multi and things just work.

i will probably turn this into an example soon.
it should be somewhat simple to actually have MultiProgress (or a wrapper of it) to implement the Log trait. i might send a pr for that in a week valve time.

@djugei
Copy link
Contributor Author

djugei commented Jul 31, 2023

probably better served by #570

@djc djc closed this as not planned Won't fix, can't repro, duplicate, stale Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants