aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/logging.cc
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/logging.cc
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/logging.cc')
-rw-r--r--src/libutil/logging.cc30
1 files changed, 26 insertions, 4 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;