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

Logging to the progress bar #124

Open
bquorning opened this issue Mar 2, 2015 · 6 comments
Open

Logging to the progress bar #124

bquorning opened this issue Mar 2, 2015 · 6 comments

Comments

@bquorning
Copy link

Directly outputting to stdout or stderr (puts or warn) doesn’t play well with ruby-progressbar. Instead, it’s recommended to call #log on the ProgressBar instance.

Would is be possible to get access to the instance of ProgressBar instantiated with Parallel?

@grosser
Copy link
Owner

grosser commented Mar 2, 2015

simple solution: pass in your own progressbar object
more elegant: Parallel.build_progressbar(options) and then pass it in
somehow storing it on Parallel would be weird since you can have multiple running at any time ...

@bbugh
Copy link

bbugh commented Dec 10, 2019

I run into this all the time still, mostly with large data migration tasks. Has there been a status change for this? If not, would it make sense for :progress option to receive a ProgressBar instance or a hash?

progress = ProgressBar.create(format: "%t (%c/%C): |%w|")
Progress.each(data, progress: progress) do |x|
  progress.log("whatever")
end

@grosser
Copy link
Owner

grosser commented Dec 10, 2019

sounds good, make a PR please :)

@bbugh
Copy link

bbugh commented Dec 11, 2019

I made a patch, but it doesn't seem promising, it still results in some uneven prints. 💩 Since the progress bar is unsynced from the parallel behavior, it's not surprising

I was hoping to tie into the mutex on parallel with a custom progressbar output class, but progressbar initializes the custom outputter and you can't override it after creation.

I'm not sure this would end up with any better results than just using puts, without a tighter integration with ruby-progressbar, and/or some way to initialize an output class within the context of parallel.

progress.log output!
progress.log output!
progress.log output!
progress.log output!th Pie 20
progress.log output!
progress.log output!
progress.log output!th Pie 20
progress.log output!
progress.log output!
progress.log output!
progress.log output!
                                                                                                                                          progress.log output!th Pie 20
progress.log output!
progress.log output!
Filling Halflings With Pie 20 ▒▒▒▒▒▒

Here's the code anyway: bbugh@f31d219

@grosser
Copy link
Owner

grosser commented Dec 12, 2019

thx for looking into it and providing some code for others to hack on :)

@ZimbiX
Copy link

ZimbiX commented Apr 29, 2021

This is super hacky, but you can access the progress bar instance with:

ObjectSpace.each_object(ProgressBar::Base).first

Calling #log on this results in clean logging.

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

4 participants