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

The log will be overwritten while the progress bar is printed #105

Closed
zhijian-pro opened this issue Feb 11, 2022 · 7 comments
Closed

The log will be overwritten while the progress bar is printed #105

zhijian-pro opened this issue Feb 11, 2022 · 7 comments

Comments

@zhijian-pro
Copy link

The log will be overwritten while the progress bar is printed.
How to set not to overwrite the log, but to move the progress bar down one line?

package main

import (
	"time"

	"github.com/sirupsen/logrus"

	"github.com/vbauerster/mpb/v7"
	"github.com/vbauerster/mpb/v7/decor"
)

var logger *logrus.Logger

func main() {
	logger = logrus.New()
	total := 10000
	p := mpb.New(mpb.WithWidth(64), mpb.WithOutput(logger.Writer()))
	b := p.AddBar(0, // disable triggerComplete
		mpb.PrependDecorators(
			decor.Name("test count: ", decor.WCSyncWidth),
			decor.CountersNoUnit("%d / %d"),
		),
		mpb.AppendDecorators(
			decor.OnComplete(decor.Percentage(decor.WC{W: 5}), "done"),
			decor.OnComplete(
				decor.AverageETA(decor.ET_STYLE_GO, decor.WC{W: 6}), "",
			),
		),
	)
	b.SetTotal(int64(total), false)

	for {
		logger.Infof(time.Now().String())
		time.Sleep(1 * time.Second)
		b.Increment()
	}
	b.SetTotal(0, true)
}

@vbauerster
Copy link
Owner

Mixing logs and progress bars at the same time is a bad idea IMHO.
Log is supposed to be printed to hard media like paper in order to be read later, while progress bar can't be printed to a paper due to its interactive nature. This is the main reason I will not accept your PR #106 no matter how good it is.

@zhijian-pro
Copy link
Author

zhijian-pro commented Jul 20, 2022

What you say is also reasonable, but undeniably, progress bar and log record both have prompt function on terminal.And logs can express information that progress bars cannot replace. For example, an exception occurs in the ninth order. This exception only affects the ninth order, not the others, so the application should continue to run, But it should also be immediately obvious to the user that there is a problem with the ninth that needs attention.
You can also see that many people have feedback on similar problems under many progress bar frameworks, which shows that this demand is common.

@venth
Copy link

venth commented Aug 24, 2022

I believe that my case is similar as @zhijian-pro. I'm looking for a multi progress bar which is capable of tracing a progress and present information about matching records. Such a solution exists in indicatif. indicatif exposes a function println which prints a message above a single or multi progress bar.

What do you think @vbauerster about extending current progress bar api by supporting of printing a message?

@vbauerster
Copy link
Owner

If you need to print something above a bar while it's running, please refer to this example.

Such a solution exists in indicatif. indicatif exposes a function println which prints a message above a single or multi progress bar.

You forgot to count unresolved issues related to that feature.

@venth
Copy link

venth commented Aug 26, 2022

Thanks for the answer and pointing out the example. I’ll take a look.

You forgot to count unresolved issues related to that feature.

That’s so true for both - forgetting and number of issues :) :) some of the issues I’ve omitted by creating a printing sequence. So it’s done in one thread.

For now, I’ve got tired of borrowing and moving in rust and went to golang. That’s why this library got my attention.

@wohenbushuang
Copy link

If you need to print something above a bar while it's running, please refer to this example.

It's complicated and seems the contents should be predefined. It will print everytime the progressbar refreshed, which may not the same as what we need (the behaviors like npm install).

vbauerster added a commit that referenced this issue Aug 31, 2022
@vbauerster
Copy link
Owner

vbauerster commented Sep 4, 2022

Implemented in v8.
https://pkg.go.dev/github.com/vbauerster/mpb/v8#Progress.Write
https://github.com/vbauerster/mpb/blob/master/_examples/progressAsWriter/main.go

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