From 2cc345b95f19334e7050c7203a5f6823af24344f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 28 Aug 2017 19:13:24 +0200 Subject: Give activities a verbosity level again And print them (separately from the progress bar) given sufficient -v flags. --- src/libutil/logging.cc | 11 +++++++++-- src/libutil/logging.hh | 8 ++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/libutil') diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc index b103b902eab0..e38a460537ea 100644 --- a/src/libutil/logging.cc +++ b/src/libutil/logging.cc @@ -45,6 +45,13 @@ public: writeToStderr(prefix + (tty ? fs.s : filterANSIEscapes(fs.s)) + "\n"); } + + void startActivity(ActivityId act, Verbosity lvl, ActivityType type, + const std::string & s, const Fields & fields, ActivityId parent) + { + if (lvl <= verbosity && !s.empty()) + log(lvl, s + "..."); + } }; Verbosity verbosity = lvlInfo; @@ -76,11 +83,11 @@ Logger * makeDefaultLogger() std::atomic nextId{(uint64_t) getpid() << 32}; -Activity::Activity(Logger & logger, ActivityType type, +Activity::Activity(Logger & logger, Verbosity lvl, ActivityType type, const std::string & s, const Logger::Fields & fields, ActivityId parent) : logger(logger), id(nextId++) { - logger.startActivity(id, type, s, fields, parent); + logger.startActivity(id, lvl, type, s, fields, parent); } } diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index e3e7c8e6f330..84fffa820f4c 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -68,7 +68,7 @@ public: virtual void warn(const std::string & msg); - virtual void startActivity(ActivityId act, ActivityType type, + virtual void startActivity(ActivityId act, Verbosity lvl, ActivityType type, const std::string & s, const Fields & fields, ActivityId parent) { }; virtual void stopActivity(ActivityId act) { }; @@ -84,9 +84,13 @@ struct Activity const ActivityId id; - Activity(Logger & logger, ActivityType type, const std::string & s = "", + Activity(Logger & logger, Verbosity lvl, ActivityType type, const std::string & s = "", const Logger::Fields & fields = {}, ActivityId parent = curActivity); + Activity(Logger & logger, ActivityType type, + const Logger::Fields & fields = {}, ActivityId parent = curActivity) + : Activity(logger, lvlError, type, "", fields, parent) { }; + Activity(const Activity & act) = delete; ~Activity() -- cgit 1.4.1