1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-28 17:51:15 +02:00

Remove "@nix" prefix from json-log-path output

This commit is contained in:
Eelco Dolstra 2025-03-13 13:37:38 +01:00
parent 2972e73946
commit 29a9e638c1
3 changed files with 19 additions and 12 deletions

View file

@ -168,8 +168,12 @@ void to_json(nlohmann::json & json, std::shared_ptr<Pos> pos)
struct JSONLogger : Logger {
Descriptor fd;
bool includeNixPrefix;
JSONLogger(Descriptor fd) : fd(fd) { }
JSONLogger(Descriptor fd, bool includeNixPrefix)
: fd(fd)
, includeNixPrefix(includeNixPrefix)
{ }
bool isVerbose() override {
return true;
@ -190,7 +194,9 @@ struct JSONLogger : Logger {
void write(const nlohmann::json & json)
{
writeLine(fd, "@nix " + json.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace));
writeLine(fd,
(includeNixPrefix ? "@nix " : "") +
json.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace));
}
void log(Verbosity lvl, std::string_view s) override
@ -262,18 +268,18 @@ struct JSONLogger : Logger {
}
};
Logger * makeJSONLogger(Descriptor fd)
Logger * makeJSONLogger(Descriptor fd, bool includeNixPrefix)
{
return new JSONLogger(fd);
return new JSONLogger(fd, includeNixPrefix);
}
Logger * makeJSONLogger(const std::filesystem::path & path)
Logger * makeJSONLogger(const std::filesystem::path & path, bool includeNixPrefix)
{
struct JSONFileLogger : JSONLogger {
AutoCloseFD fd;
JSONFileLogger(AutoCloseFD && fd)
: JSONLogger(fd.get())
JSONFileLogger(AutoCloseFD && fd, bool includeNixPrefix)
: JSONLogger(fd.get(), includeNixPrefix)
, fd(std::move(fd))
{ }
};
@ -282,7 +288,7 @@ Logger * makeJSONLogger(const std::filesystem::path & path)
if (!fd)
throw SysError("opening log file '%1%'", path);
return new JSONFileLogger(std::move(fd));
return new JSONFileLogger(std::move(fd), includeNixPrefix);
}
static Logger::Fields getFields(nlohmann::json & json)

View file

@ -189,9 +189,9 @@ Logger * makeSimpleLogger(bool printBuildLogs = true);
Logger * makeTeeLogger(std::vector<Logger *> loggers);
Logger * makeJSONLogger(Descriptor fd);
Logger * makeJSONLogger(Descriptor fd, bool includeNixPrefix = true);
Logger * makeJSONLogger(const std::filesystem::path & path);
Logger * makeJSONLogger(const std::filesystem::path & path, bool includeNixPrefix = true);
/**
* @param source A noun phrase describing the source of the message, e.g. "the builder".

View file

@ -354,7 +354,8 @@ struct ExtLoggerSettings : Config
this, "", "json-log-path",
R"(
A path to which JSON records of Nix's log output will be
written, in the same format as `--log-format internal-json`.
written, in the same format as `--log-format internal-json`
(without the `@nix ` prefixes on each line).
)"};
};
@ -501,7 +502,7 @@ void mainWrapped(int argc, char * * argv)
}
if (!extLoggerSettings.jsonLogPath.get().empty()) {
logger = makeTeeLogger({logger, makeJSONLogger(std::filesystem::path(extLoggerSettings.jsonLogPath.get()))});
logger = makeTeeLogger({logger, makeJSONLogger(std::filesystem::path(extLoggerSettings.jsonLogPath.get()), false)});
}
if (args.helpRequested) {