1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-30 06:01:00 +01:00

Merge remote-tracking branch 'origin/master' into tmp

This commit is contained in:
Eelco Dolstra 2022-12-20 13:50:16 +01:00
commit 15d2e0e63b
12 changed files with 85 additions and 85 deletions

View file

@ -131,6 +131,21 @@ Activity::Activity(Logger & logger, Verbosity lvl, ActivityType type,
logger.startActivity(id, lvl, type, s, fields, parent);
}
void to_json(nlohmann::json & json, std::shared_ptr<AbstractPos> pos)
{
if (pos) {
json["line"] = pos->line;
json["column"] = pos->column;
std::ostringstream str;
pos->print(str);
json["file"] = str.str();
} else {
json["line"] = nullptr;
json["column"] = nullptr;
json["file"] = nullptr;
}
}
struct JSONLogger : Logger {
Logger & prevLogger;
@ -177,29 +192,14 @@ struct JSONLogger : Logger {
json["level"] = ei.level;
json["msg"] = oss.str();
json["raw_msg"] = ei.msg.str();
if (ei.errPos) {
json["line"] = ei.errPos->line;
json["column"] = ei.errPos->column;
//json["file"] = ei.errPos->file;
json["file"] = nullptr;
} else {
json["line"] = nullptr;
json["column"] = nullptr;
json["file"] = nullptr;
}
to_json(json, ei.errPos);
if (loggerSettings.showTrace.get() && !ei.traces.empty()) {
nlohmann::json traces = nlohmann::json::array();
for (auto iter = ei.traces.rbegin(); iter != ei.traces.rend(); ++iter) {
nlohmann::json stackFrame;
stackFrame["raw_msg"] = iter->hint.str();
if (iter->pos) {
stackFrame["line"] = iter->pos->line;
stackFrame["column"] = iter->pos->column;
//stackFrame["file"] = iter->pos->file;
stackFrame["file"] = nullptr;
}
to_json(stackFrame, iter->pos);
traces.push_back(stackFrame);
}