Improved logging abstraction

This also gets rid of --log-type, since the nested log type isn't
useful in a multi-threaded situation, and nobody cares about the
"pretty" log type.
This commit is contained in:
Eelco Dolstra 2016-04-25 15:26:07 +02:00
parent c879a20850
commit 41633f9f73
29 changed files with 394 additions and 456 deletions

View file

@ -1,5 +1,4 @@
#include "command.hh"
#include "progress-bar.hh"
#include "shared.hh"
#include "store-api.hh"
#include "thread-pool.hh"
@ -38,21 +37,15 @@ struct CmdCopySigs : StorePathsCommand
for (auto & s : substituterUris)
substituters.push_back(openStoreAt(s));
ProgressBar progressBar;
ThreadPool pool;
std::atomic<size_t> done{0};
std::string doneLabel = "done";
std::atomic<size_t> added{0};
auto showProgress = [&]() {
return (format("[%d/%d done]") % done % storePaths.size()).str();
};
progressBar.updateStatus(showProgress());
logger->setExpected(doneLabel, storePaths.size());
auto doPath = [&](const Path & storePath) {
auto activity(progressBar.startActivity(format("getting signatures for %s") % storePath));
Activity act(*logger, lvlInfo, format("getting signatures for %s") % storePath);
checkInterrupt();
@ -83,8 +76,7 @@ struct CmdCopySigs : StorePathsCommand
added += newSigs.size();
}
done++;
progressBar.updateStatus(showProgress());
logger->incProgress(doneLabel);
};
for (auto & storePath : storePaths)
@ -92,8 +84,6 @@ struct CmdCopySigs : StorePathsCommand
pool.process();
progressBar.done();
printMsg(lvlInfo, format("imported %d signatures") % added);
}
};