schollz / progressbar

A really basic thread-safe progress bar for Golang applications

Home Page:https://pkg.go.dev/github.com/schollz/progressbar/v3?tab=doc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Other logs while progressbar is running

chirag-ghosh opened this issue · comments

If other logs are printed while the progressbar runs, this happens
image

Is there a way to remove those leftover progressbar lines?

commented

what you do mean exactly? you want things to be logged and also show a progressbar, like at the bottom of the terminal?

you could log to a file instead and track the log there instead of in the same stdout

what you do mean exactly? you want things to be logged and also show a progressbar, like at the bottom of the terminal?

Yes

you could log to a file instead and track the log there instead of in the same stdout

Sure but I wanted to log to the terminal itself and wondered if there's a way. Not a big deal though

I do this by clearing the bar, logging what I need to, and then re-rendering the bar, like

pBar.Clear()
logStuff()
pBar.RenderBlank()

It works, but you'll need to make sure there aren't concurrent progress bar updates, there isn't any inappropriate buffering, etc.

commented

good advice @csw, it is tricky though if you have multiple logging lines and have to sandwich all of them.

@chirag-ghosh you might need to look at another project like mpb or something (not sure if that doesn't either). I think generally logging + progressbars are not a thing...I've only seen them in the docker build functions so maybe that codebase will give you a hint (though I bet its complicated).

I'm closing this because its not part of the scope