mirror of
https://github.com/NixOS/nix
synced 2025-06-27 16:51:15 +02:00
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)
This commit is contained in:
parent
2c4de6af10
commit
4983401440
7 changed files with 46 additions and 20 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue