Mpdreamz / shellprogressbar

ShellProgressBar - display progress in your console application
MIT License
1.43k stars 134 forks source link

Does not play well with logging #54

Open eiredrake opened 4 years ago

eiredrake commented 4 years ago

I've got a console app that I'm looking to have a displayed progress (two layers deep) but also have log output to the console.

Unfortunately the logger (Serilog in my case) and ShellProgressBar don't play well with each other and are constantly overwriting each other which leaves the console an incomprehensible mess. Is there any way to prevent this or do I need to research how to make a custom Serilog console sink? Like maybe somehow force it to stick to certain lines or percentage of the screen or something?

thanks, E

Mpdreamz commented 4 years ago

I briefly investigated this to submit a PR to Serilog.Sinks.Console to inject a custom TextWriter for standard out and error.

That could possibly work but the sink also actively changes Console.ForegroundColor expecting the sink to write in real time.

That said you can now write persist message above the console using pbar.WriteLine() and I've opened #59 so you can also write to standard error above the console. A custom sink link Serilog.Sinks.Console.ShellProgressBar could work but it won't be able to reuse much of the infrastructure of Serilog.Sinks.Console since most is private/internal.

Will leave this open as I think this project should also build a Serilog.Sinks.ShellProgressBar to validate its design and interopability with logging frameworks. It won't be anywhere near as fully featured.

That said the progressbar pbar.WriteLine() is only to persist and preserve important messages above the progress bar. It's inherently slow as it needs to buffer and flush in sync with the progressbar draw loop. So it would make a poor logger for anything with high volume logging.

jerone commented 4 years ago

I'm having the same issue with Microsoft's default logging extension, using the ILogger from Microsoft.Extensions.Logging.

The implementation currently contains multiple ProgressBar, separated with _logger.LogInformation("msg"); from Microsoft.Extensions.Logging. The logger lines are being immediately overwritten by the next ProgressBar.

Mart-Bogdan commented 3 years ago

I've seen nodejs libs for pogressbar that allows console outut, just pogressbar renders on bottom of a screen

Mart-Bogdan commented 3 years ago

It's seems we can use _pbar. WriteLine but id don't display all lines correctly!