How to work with logging and progress bar in a node.js CLI application?

Viewed 903

Context

In the Node.js application, I use:

The CLI application will display a progress bar when building files. During the build operation, sometimes information/errors need to be logged to the console. This disturbs the progress bar in that:

  • the info/error logs to the console immediately after the progress bar and not on a newline
  • the progress bar gets printed again after the logs have finished, resulting in multiple progress bars printed in the console

Illustration of the console:

[===========----------------------] 11 / 33 builtwarn: something wrong here.
[=============--------------------] 13 / 33 builtwarn: something wrong here.
warn: example warning that continues here.
error:  some stacktrace
[=================================] 33 / 33 built

Question

Is there a way to ensure that the progress bar is not disturbed and any information logs to the console are printed above/below the bar? Such that only one progress bar is shown.

I understand that there's a interrupt method in node-progress, but I am not sure how to use that with winston.

I would imagine this to be a fairly common scenario in CLI applications so any suggestions/ideas of how to do it via other dependencies/approaches are appreciated too!

0 Answers
Related