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

Feature Request: progress monitor #854

Closed
epruesse opened this issue Oct 2, 2018 · 3 comments
Closed

Feature Request: progress monitor #854

epruesse opened this issue Oct 2, 2018 · 3 comments

Comments

@epruesse
Copy link
Contributor

epruesse commented Oct 2, 2018

It would be neat to have a progress monitor integrated with spdlog. Something to be used like this:

auto p = spdlog::progress(logger, container, "Doing something");
for (auto& i : container) {
    ...
    ++p
}

or even

for (auto& i :  progress(logger, container, msg)) {
    ...
}

Ideally, it'd use terminal magic from the sink where available to show a pretty bar at the bottom with messages scrolling away above, or minimal output if the sink is a file.

Something like TQDM (which is actually quite fast).

The most basic implementation is so simple, most progress displays are probably home-built. Looking at the above, though, there are quite a few niceties that can't be justified when written for a single project. Loggerhead implements a progress bar using spdlog and might serve as a starting point.

@epruesse
Copy link
Contributor Author

epruesse commented Oct 2, 2018

Hmm. A nice bar is really useful only interactively, so stdout, ansicolor and wincolor sinks.

What it'd need is a way to intercept the line-writes, so that it can issue command codes to move the cursor as needed. Right now those are direct fwrites to a FILE*. The sinks are already templated, though. Any reason why fwrite and fflush can't be moved to the TargetStream, so that an alternate TargetStream might handle interception?

@gabime
Copy link
Owner

gabime commented Oct 2, 2018

Nice Idea, but I think it is not very easy to achieve (esp. without breaking the existing API).

A possible approach would be a new sink type (e.g. "progress_sink") that destructs when progress is complete:

template<typename Container>
void spdlog::progress(const std::string &logger_name, const Container &container)
{
   progress_sink  the_sink(container.size())  /*total steps */);
   for (auto& i : container)
   {
      the_sink.log_step(...)
  } //progress_sink  dies here. add newline or whatever in its destructor
 }

What it'd need is a way to intercept the line-writes, so that it can issue command codes to move the cursor as needed

I think it can done be in the constructing a formatter with custom eol. Each sink owns its own private formatter instance.

@gabime gabime closed this as completed Oct 12, 2018
@epruesse
Copy link
Contributor Author

If I find the time, I may still look into this.

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

2 participants