mirror of
https://github.com/NixOS/nix.git
synced 2025-11-13 05:56:03 +01:00
Merge remote-tracking branch 'upstream/master' into enum-class
This commit is contained in:
commit
40526fbea5
158 changed files with 3027 additions and 1816 deletions
|
|
@ -18,7 +18,7 @@ void setCurActivity(const ActivityId activityId)
|
|||
curActivity = activityId;
|
||||
}
|
||||
|
||||
Logger * logger = makeDefaultLogger();
|
||||
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;
|
||||
|
|
@ -63,13 +69,33 @@ public:
|
|||
writeToStderr(prefix + filterANSIEscapes(fs.s, !tty) + "\n");
|
||||
}
|
||||
|
||||
void logEI(const ErrorInfo & ei) override
|
||||
{
|
||||
std::stringstream oss;
|
||||
oss << ei;
|
||||
|
||||
log(ei.level, oss.str());
|
||||
}
|
||||
|
||||
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
|
||||
const std::string & s, const Fields & fields, ActivityId parent)
|
||||
override
|
||||
override
|
||||
{
|
||||
if (lvl <= verbosity && !s.empty())
|
||||
log(lvl, s + "...");
|
||||
}
|
||||
|
||||
void result(ActivityId act, ResultType type, const Fields & fields) override
|
||||
{
|
||||
if (type == ResultType::BuildLogLine && printBuildLogs) {
|
||||
auto lastLine = fields[0].s;
|
||||
printError(lastLine);
|
||||
}
|
||||
else if (type == ResultType::PostBuildLogLine && printBuildLogs) {
|
||||
auto lastLine = fields[0].s;
|
||||
printError("post-build-hook: " + lastLine);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Verbosity verbosity = Verbosity::Info;
|
||||
|
|
@ -94,9 +120,9 @@ void writeToStderr(const string & s)
|
|||
}
|
||||
}
|
||||
|
||||
Logger * makeDefaultLogger()
|
||||
Logger * makeSimpleLogger(bool printBuildLogs)
|
||||
{
|
||||
return new SimpleLogger();
|
||||
return new SimpleLogger(printBuildLogs);
|
||||
}
|
||||
|
||||
std::atomic<uint64_t> nextId{(uint64_t) getpid() << 32};
|
||||
|
|
@ -108,12 +134,15 @@ Activity::Activity(Logger & logger, Verbosity lvl, ActivityType type,
|
|||
logger.startActivity(id, lvl, type, s, fields, parent);
|
||||
}
|
||||
|
||||
struct JSONLogger : Logger
|
||||
{
|
||||
struct JSONLogger : Logger {
|
||||
Logger & prevLogger;
|
||||
|
||||
JSONLogger(Logger & prevLogger) : prevLogger(prevLogger) { }
|
||||
|
||||
bool isVerbose() override {
|
||||
return true;
|
||||
}
|
||||
|
||||
void addFields(nlohmann::json & json, const Fields & fields)
|
||||
{
|
||||
if (fields.empty()) return;
|
||||
|
|
@ -141,6 +170,19 @@ struct JSONLogger : Logger
|
|||
write(json);
|
||||
}
|
||||
|
||||
void logEI(const ErrorInfo & ei) override
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << ei;
|
||||
|
||||
nlohmann::json json;
|
||||
json["action"] = "msg";
|
||||
json["level"] = ei.level;
|
||||
json["msg"] = oss.str();
|
||||
|
||||
write(json);
|
||||
}
|
||||
|
||||
void startActivity(ActivityId act, Verbosity lvl, ActivityType type,
|
||||
const std::string & s, const Fields & fields, ActivityId parent) override
|
||||
{
|
||||
|
|
@ -231,13 +273,17 @@ bool handleJSONLogMessage(const std::string & msg,
|
|||
}
|
||||
|
||||
} catch (std::exception & e) {
|
||||
printError("bad log message from builder: %s", e.what());
|
||||
logError({
|
||||
.name = "Json log message",
|
||||
.hint = hintfmt("bad log message from builder: %s", e.what())
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Activity::~Activity() {
|
||||
Activity::~Activity()
|
||||
{
|
||||
try {
|
||||
logger.stopActivity(id);
|
||||
} catch (...) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue