mirror of
https://github.com/NixOS/nix
synced 2025-06-28 22:01:15 +02:00
Remove "@nix" prefix from json-log-path output
This commit is contained in:
parent
2972e73946
commit
29a9e638c1
3 changed files with 19 additions and 12 deletions
|
@ -168,8 +168,12 @@ void to_json(nlohmann::json & json, std::shared_ptr<Pos> pos)
|
||||||
|
|
||||||
struct JSONLogger : Logger {
|
struct JSONLogger : Logger {
|
||||||
Descriptor fd;
|
Descriptor fd;
|
||||||
|
bool includeNixPrefix;
|
||||||
|
|
||||||
JSONLogger(Descriptor fd) : fd(fd) { }
|
JSONLogger(Descriptor fd, bool includeNixPrefix)
|
||||||
|
: fd(fd)
|
||||||
|
, includeNixPrefix(includeNixPrefix)
|
||||||
|
{ }
|
||||||
|
|
||||||
bool isVerbose() override {
|
bool isVerbose() override {
|
||||||
return true;
|
return true;
|
||||||
|
@ -190,7 +194,9 @@ struct JSONLogger : Logger {
|
||||||
|
|
||||||
void write(const nlohmann::json & json)
|
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
|
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 {
|
struct JSONFileLogger : JSONLogger {
|
||||||
AutoCloseFD fd;
|
AutoCloseFD fd;
|
||||||
|
|
||||||
JSONFileLogger(AutoCloseFD && fd)
|
JSONFileLogger(AutoCloseFD && fd, bool includeNixPrefix)
|
||||||
: JSONLogger(fd.get())
|
: JSONLogger(fd.get(), includeNixPrefix)
|
||||||
, fd(std::move(fd))
|
, fd(std::move(fd))
|
||||||
{ }
|
{ }
|
||||||
};
|
};
|
||||||
|
@ -282,7 +288,7 @@ Logger * makeJSONLogger(const std::filesystem::path & path)
|
||||||
if (!fd)
|
if (!fd)
|
||||||
throw SysError("opening log file '%1%'", path);
|
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)
|
static Logger::Fields getFields(nlohmann::json & json)
|
||||||
|
|
|
@ -189,9 +189,9 @@ Logger * makeSimpleLogger(bool printBuildLogs = true);
|
||||||
|
|
||||||
Logger * makeTeeLogger(std::vector<Logger *> loggers);
|
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".
|
* @param source A noun phrase describing the source of the message, e.g. "the builder".
|
||||||
|
|
|
@ -354,7 +354,8 @@ struct ExtLoggerSettings : Config
|
||||||
this, "", "json-log-path",
|
this, "", "json-log-path",
|
||||||
R"(
|
R"(
|
||||||
A path to which JSON records of Nix's log output will be
|
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()) {
|
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) {
|
if (args.helpRequested) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue