aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorregnat <rg@regnat.ovh>2020-06-05 18:20:11 +0200
committerregnat <rg@regnat.ovh>2020-06-08 09:31:15 +0200
commit4983401440e1c46d6c576bc36ac86169bd296f9f (patch)
treedc9b7483acc503a29023fc292a414c32100a0e4b /src/libutil
parent2c4de6af1033367168320f43b0f04062bdac9234 (diff)
Unify the printing of the logs between bar-with-logs and raw
Make the printing of the build logs systematically go through the logger, and replicate the behavior of `no-build-output` by having two different loggers (one that prints the build logs and one that doesn't)
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/logging.cc30
-rw-r--r--src/libutil/logging.hh5
2 files changed, 30 insertions, 5 deletions
diff --git a/src/libutil/logging.cc b/src/libutil/logging.cc
index 6aec16e58..15cbc1589 100644
--- a/src/libutil/logging.cc
+++ b/src/libutil/logging.cc
@@ -18,7 +18,7 @@ void setCurActivity(const ActivityId activityId)
curActivity = activityId;
}
-Logger * logger = makeSimpleLogger();
+Logger * logger = makeSimpleLogger(true);
void Logger::warn(const std::string & msg)
{
@@ -35,13 +35,19 @@ class SimpleLogger : public Logger
public:
bool systemd, tty;
+ bool printBuildLogs;
- SimpleLogger()
+ SimpleLogger(bool printBuildLogs)
+ : printBuildLogs(printBuildLogs)
{
systemd = getEnv("IN_SYSTEMD") == "1";
tty = isatty(STDERR_FILENO);
}
+ bool isVerbose() override {
+ return printBuildLogs;
+ }
+
void log(Verbosity lvl, const FormatOrString & fs) override
{
if (lvl > verbosity) return;
@@ -70,6 +76,18 @@ public:
if (lvl <= verbosity && !s.empty())
log(lvl, s + "...");
}
+
+ void result(ActivityId act, ResultType type, const Fields & fields) override
+ {
+ if (type == resBuildLogLine && printBuildLogs) {
+ auto lastLine = fields[0].s;
+ printError(lastLine);
+ }
+ else if (type == resPostBuildLogLine && printBuildLogs) {
+ auto lastLine = fields[0].s;
+ printError("post-build-hook: " + lastLine);
+ }
+ }
};
Verbosity verbosity = lvlInfo;
@@ -94,9 +112,9 @@ void writeToStderr(const string & s)
}
}
-Logger * makeSimpleLogger()
+Logger * makeSimpleLogger(bool printBuildLogs)
{
- return new SimpleLogger();
+ return new SimpleLogger(printBuildLogs);
}
std::atomic<uint64_t> nextId{(uint64_t) getpid() << 32};
@@ -114,6 +132,10 @@ struct JSONLogger : Logger
JSONLogger(Logger & prevLogger) : prevLogger(prevLogger) { }
+ bool isVerbose() override {
+ return true;
+ }
+
void addFields(nlohmann::json & json, const Fields & fields)
{
if (fields.empty()) return;
diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh
index e319790fc..e3d91e01f 100644
--- a/src/libutil/logging.hh
+++ b/src/libutil/logging.hh
@@ -65,6 +65,9 @@ public:
virtual void stop() { };
+ // Whether the logger prints the whole build log
+ virtual bool isVerbose() { return false; }
+
virtual void log(Verbosity lvl, const FormatOrString & fs) = 0;
void log(const FormatOrString & fs)
@@ -143,7 +146,7 @@ struct PushActivity
extern Logger * logger;
-Logger * makeSimpleLogger();
+Logger * makeSimpleLogger(bool printBuildLogs = true);
Logger * makeJSONLogger(Logger & prevLogger);