aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-04-16 13:12:58 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-04-16 13:47:59 +0200
commit696c026006a6ac46adc990ed5cb0f31535bac076 (patch)
tree73b1d7b97acdff3537a3189ddb20ccba319afe45 /src/libutil
parent3729df34da524e9f42ce86b83a762dd3da6f7384 (diff)
Logger: Add method for writing to stdout
Usually this just writes to stdout, but for ProgressBar, we need to clear the current line, write the line to stdout, and then redraw the progress bar.
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/logging.cc6
-rw-r--r--src/libutil/logging.hh10
2 files changed, 16 insertions, 0 deletions
diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc
index bb437cf1c..3cc4ef8f1 100644
--- a/src/libutil/logging.cc
+++ b/src/libutil/logging.cc
@@ -3,6 +3,7 @@
#include <atomic>
#include <nlohmann/json.hpp>
+#include <iostream>
namespace nix {
@@ -24,6 +25,11 @@ void Logger::warn(const std::string & msg)
log(lvlWarn, ANSI_YELLOW "warning:" ANSI_NORMAL " " + msg);
}
+void Logger::writeToStdout(std::string_view s)
+{
+ std::cout << s << "\n";
+}
+
class SimpleLogger : public Logger
{
public:
diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh
index 108b5dcb0..18c24d508 100644
--- a/src/libutil/logging.hh
+++ b/src/libutil/logging.hh
@@ -78,6 +78,16 @@ public:
virtual void stopActivity(ActivityId act) { };
virtual void result(ActivityId act, ResultType type, const Fields & fields) { };
+
+ virtual void writeToStdout(std::string_view s);
+
+ template<typename... Args>
+ inline void stdout(const std::string & fs, const Args & ... args)
+ {
+ boost::format f(fs);
+ formatHelper(f, args...);
+ writeToStdout(f.str());
+ }
};
ActivityId getCurActivity();