about summary refs log tree commit diff
path: root/src/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/logging.cc5
-rw-r--r--src/libutil/logging.hh13
-rw-r--r--src/libutil/types.hh1
-rw-r--r--src/libutil/util.hh14
4 files changed, 21 insertions, 12 deletions
diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc
index 321c90712917..ed83770a14aa 100644
--- a/src/libutil/logging.cc
+++ b/src/libutil/logging.cc
@@ -91,4 +91,9 @@ Activity::~Activity()
     logger->event(evStopActivity, id);
 }
 
+void Activity::progress(uint64_t done, uint64_t expected, uint64_t running, uint64_t failed) const
+{
+    logger->event(evProgress, id, done, expected, running, failed);
+}
+
 }
diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh
index f3ff099f0cec..b6ab3d7d3b8f 100644
--- a/src/libutil/logging.hh
+++ b/src/libutil/logging.hh
@@ -32,8 +32,7 @@ public:
     Activity(ActivityType type, std::string msg = "");
     ~Activity();
 
-    template<typename... Args>
-    void progress(const Args & ... args) const;
+    void progress(uint64_t done = 0, uint64_t expected = 0, uint64_t running = 0, uint64_t failed = 0) const;
 };
 
 typedef enum {
@@ -146,14 +145,4 @@ void warnOnce(bool & haveWarned, const FormatOrString & fs);
 
 void writeToStderr(const string & s);
 
-template<typename... Args>
-void Activity::progress(const Args & ... args) const
-{
-    Event ev;
-    ev.type = evProgress;
-    ev.fields.emplace_back(id);
-    nop{(ev.fields.emplace_back(Event::Field(args)), 1)...};
-    logger->event(ev);
-}
-
 }
diff --git a/src/libutil/types.hh b/src/libutil/types.hh
index 9f32d31addbf..92bf469b5c6f 100644
--- a/src/libutil/types.hh
+++ b/src/libutil/types.hh
@@ -70,6 +70,7 @@ template<typename... Args>
 inline std::string fmt(const std::string & fs, Args... args)
 {
     boost::format f(fs);
+    f.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit);
     nop{boost::io::detail::feed(f, args)...};
     return f.str();
 }
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index f37f2c5d1be5..35909c8d5b31 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -462,4 +462,18 @@ struct ReceiveInterrupts
     { }
 };
 
+
+
+/* A RAII helper that increments a counter on construction and
+   decrements it on destruction. */
+template<typename T>
+struct MaintainCount
+{
+    T & counter;
+    long delta;
+    MaintainCount(T & counter, long delta = 1) : counter(counter), delta(delta) { counter += delta; }
+    ~MaintainCount() { counter -= delta; }
+};
+
+
 }