about summary refs log tree commit diff
path: root/src/libutil/logging.hh
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-08-25T12·53+0200
committerEelco Dolstra <edolstra@gmail.com>2017-08-25T13·58+0200
commit0e9ddcc306f0900fc38472a2c8b9d9aa886b279e (patch)
tree564883e41ee9aee98ec1bdceed43f7d2be8f905b /src/libutil/logging.hh
parent1f56235438984d8079159d7c81ad4127c318b2dc (diff)
Restore activity metadata
This allows the progress bar to display "building perl-5.22.3" instead
of "building /nix/store/<hash>-perl-5.22.3.drv".
Diffstat (limited to 'src/libutil/logging.hh')
-rw-r--r--src/libutil/logging.hh34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh
index 08a11617591e..567af361e8e9 100644
--- a/src/libutil/logging.hh
+++ b/src/libutil/logging.hh
@@ -40,6 +40,19 @@ class Logger
 
 public:
 
+    struct Field
+    {
+        // FIXME: use std::variant.
+        enum { tInt, tString } type;
+        uint64_t i = 0;
+        std::string s;
+        Field(const std::string & s) : type(tString), s(s) { }
+        Field(const char * s) : type(tString), s(s) { }
+        Field(const uint64_t & i) : type(tInt), i(i) { }
+    };
+
+    typedef std::vector<Field> Fields;
+
     virtual ~Logger() { }
 
     virtual void log(Verbosity lvl, const FormatOrString & fs) = 0;
@@ -51,7 +64,8 @@ public:
 
     virtual void warn(const std::string & msg);
 
-    virtual void startActivity(ActivityId act, ActivityType type, const std::string & s) { };
+    virtual void startActivity(ActivityId act, ActivityType type,
+        const std::string & s, const Fields & fields) { };
 
     virtual void stopActivity(ActivityId act) { };
 
@@ -59,18 +73,7 @@ public:
 
     virtual void setExpected(ActivityId act, ActivityType type, uint64_t expected) { };
 
-    struct Field
-    {
-        // FIXME: use std::variant.
-        enum { tInt, tString } type;
-        uint64_t i = 0;
-        std::string s;
-        Field(const std::string & s) : type(tString), s(s) { }
-        Field(const char * s) : type(tString), s(s) { }
-        Field(const uint64_t & i) : type(tInt), i(i) { }
-    };
-
-    virtual void result(ActivityId act, ResultType type, const std::vector<Field> & fields) { };
+    virtual void result(ActivityId act, ResultType type, const Fields & fields) { };
 };
 
 struct Activity
@@ -79,7 +82,8 @@ struct Activity
 
     const ActivityId id;
 
-    Activity(Logger & logger, ActivityType type, const std::string & s = "");
+    Activity(Logger & logger, ActivityType type, const std::string & s = "",
+        const Logger::Fields & fields = {});
 
     Activity(const Activity & act) = delete;
 
@@ -95,7 +99,7 @@ struct Activity
     template<typename... Args>
     void result(ResultType type, const Args & ... args)
     {
-        std::vector<Logger::Field> fields;
+        Logger::Fields fields;
         nop{(fields.emplace_back(Logger::Field(args)), 1)...};
         logger.result(id, type, fields);
     }