mirror of
https://github.com/NixOS/nix
synced 2025-07-01 16:41:47 +02:00
Logger::result(): Support logging arbitrary JSON objects
This commit is contained in:
parent
220000dc1a
commit
2a2af3f72f
4 changed files with 27 additions and 4 deletions
|
@ -2656,11 +2656,11 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
|
||||||
worker.store.printStorePath(drvPath),
|
worker.store.printStorePath(drvPath),
|
||||||
wanted.to_string(HashFormat::SRI, true),
|
wanted.to_string(HashFormat::SRI, true),
|
||||||
got.to_string(HashFormat::SRI, true)));
|
got.to_string(HashFormat::SRI, true)));
|
||||||
// FIXME: put this in BuildResult and log that as JSON.
|
|
||||||
act->result(resHashMismatch,
|
act->result(resHashMismatch,
|
||||||
{worker.store.printStorePath(drvPath),
|
{
|
||||||
wanted.to_string(HashFormat::SRI, true),
|
{"storePath", worker.store.printStorePath(drvPath)},
|
||||||
got.to_string(HashFormat::SRI, true)
|
{"wanted", wanted.to_string(HashFormat::SRI, true)},
|
||||||
|
{"got", got.to_string(HashFormat::SRI, true)},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!newInfo0.references.empty()) {
|
if (!newInfo0.references.empty()) {
|
||||||
|
|
|
@ -279,6 +279,16 @@ struct JSONLogger : Logger {
|
||||||
addFields(json, fields);
|
addFields(json, fields);
|
||||||
write(json);
|
write(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void result(ActivityId act, ResultType type, const nlohmann::json & j) override
|
||||||
|
{
|
||||||
|
nlohmann::json json;
|
||||||
|
json["action"] = "result";
|
||||||
|
json["id"] = act;
|
||||||
|
json["type"] = type;
|
||||||
|
json["payload"] = j;
|
||||||
|
write(json);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Logger * makeJSONLogger(Descriptor fd, bool includeNixPrefix)
|
Logger * makeJSONLogger(Descriptor fd, bool includeNixPrefix)
|
||||||
|
|
|
@ -108,6 +108,8 @@ public:
|
||||||
|
|
||||||
virtual void result(ActivityId act, ResultType type, const Fields & fields) { };
|
virtual void result(ActivityId act, ResultType type, const Fields & fields) { };
|
||||||
|
|
||||||
|
virtual void result(ActivityId act, ResultType type, const nlohmann::json & json) { };
|
||||||
|
|
||||||
virtual void writeToStdout(std::string_view s);
|
virtual void writeToStdout(std::string_view s);
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
|
@ -160,6 +162,11 @@ struct Activity
|
||||||
void setExpected(ActivityType type2, uint64_t expected) const
|
void setExpected(ActivityType type2, uint64_t expected) const
|
||||||
{ result(resSetExpected, type2, expected); }
|
{ result(resSetExpected, type2, expected); }
|
||||||
|
|
||||||
|
void result(ResultType type, const nlohmann::json & json) const
|
||||||
|
{
|
||||||
|
logger.result(id, type, json);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void result(ResultType type, const Args & ... args) const
|
void result(ResultType type, const Args & ... args) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -65,6 +65,12 @@ struct TeeLogger : Logger
|
||||||
logger->result(act, type, fields);
|
logger->result(act, type, fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void result(ActivityId act, ResultType type, const nlohmann::json & json) override
|
||||||
|
{
|
||||||
|
for (auto & logger : loggers)
|
||||||
|
logger->result(act, type, json);
|
||||||
|
}
|
||||||
|
|
||||||
void writeToStdout(std::string_view s) override
|
void writeToStdout(std::string_view s) override
|
||||||
{
|
{
|
||||||
for (auto & logger : loggers) {
|
for (auto & logger : loggers) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue