Skip to content

Commit

Permalink
Drop the custom external json logger
Browse files Browse the repository at this point in the history
Use the internal one instead. This has the drawback that the internal
logger is not as user-friendly as the old one (because of its use of
magic numbers), but that makes maintenance much simpler.
  • Loading branch information
thufschmitt committed Sep 2, 2019
1 parent 6bd7b9e commit 1e893d4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 77 deletions.
67 changes: 1 addition & 66 deletions src/libmain/loggers.cc
Expand Up @@ -31,77 +31,12 @@ LogFormat parseLogFormat(const string &logFormatStr) {
logFormatStr);
}

/**
* A json logger intended for external consumption
* (contrary to 'JSONLogger' which is an internal thing
*/
struct ExternalJSONLogger : JSONLogger {
ExternalJSONLogger(Logger &prevLogger) : JSONLogger(prevLogger) {}

nlohmann::json jsonActivityType(ActivityType type) override {
switch (type) {
case actUnknown:
return "actUnknown";
case actCopyPath:
return "actCopyPath";
case actDownload:
return "actDownload";
case actRealise:
return "actRealise";
case actCopyPaths:
return "actCopyPaths";
case actBuilds:
return "actBuilds";
case actBuild:
return "actBuild";
case actOptimiseStore:
return "actOptimiseStore";
case actVerifyPaths:
return "actVerifyPaths";
case actSubstitute:
return "actSubstitute";
case actQueryPathInfo:
return "actQueryPathInfo";
case actPostBuildHook:
return "actPostBuildHook";
default:
return "UnknownActivity";
}
}

nlohmann::json jsonResultType(ResultType type) override {
switch (type) {
case resFileLinked:
return "resFileLinked";
case resBuildLogLine:
return "resBuildLogLine";
case resUntrustedPath:
return "resUntrustedPath";
case resCorruptedPath:
return "resCorruptedPath";
case resSetPhase:
return "resSetPhase";
case resProgress:
return "resProgress";
case resSetExpected:
return "resSetExpected";
case resPostBuildLogLine:
return "resPostBuildLogLine";
default:
return "UnknownResultType";
}
}

void result(ActivityId act, ResultType type,
const Fields &fields) override{};
};

Logger *makeDefaultLogger() {
switch (logFormat) {
case logFormatRaw:
return makeSimpleLogger();
case logFormatJSON:
return new ExternalJSONLogger(*makeSimpleLogger());
return new JSONLogger();
case logFormatBar:
return createProgressBar();
case logFormatBarWithLogs:
Expand Down
8 changes: 2 additions & 6 deletions src/libutil/json-logger.cc
Expand Up @@ -10,10 +10,6 @@ JSONLogger::JSONLogger(Logger &prevLogger) : prevLogger(prevLogger) {}

JSONLogger::JSONLogger() : JSONLogger(*makeSimpleLogger()) {}

nlohmann::json JSONLogger::jsonActivityType(ActivityType type) { return type; }

nlohmann::json JSONLogger::jsonResultType(ResultType type) { return type; }

void JSONLogger::addFields(nlohmann::json &json, const Fields &fields) {
if (fields.empty())
return;
Expand Down Expand Up @@ -46,7 +42,7 @@ void JSONLogger::startActivity(ActivityId act, Verbosity lvl, ActivityType type,
json["action"] = "start";
json["id"] = act;
json["level"] = lvl;
json["type"] = jsonActivityType(type);
json["type"] = type;
json["text"] = s;
addFields(json, fields);
// FIXME: handle parent
Expand All @@ -64,7 +60,7 @@ void JSONLogger::result(ActivityId act, ResultType type, const Fields &fields) {
nlohmann::json json;
json["action"] = "result";
json["id"] = act;
json["type"] = jsonResultType(type);
json["type"] = type;
addFields(json, fields);
write(json);
}
Expand Down
5 changes: 0 additions & 5 deletions src/libutil/json-logger.hh
Expand Up @@ -32,11 +32,6 @@ class JSONLogger : public Logger {
virtual void stopActivity(ActivityId act);

virtual void result(ActivityId act, ResultType type, const Fields &fields);

protected:
virtual nlohmann::json jsonActivityType(ActivityType type);

virtual nlohmann::json jsonResultType(ResultType type);
};

/**
Expand Down

0 comments on commit 1e893d4

Please sign in to comment.