2020-06-05 15:01:02 +00:00
|
|
|
#include "loggers.hh"
|
2020-06-08 15:16:52 +00:00
|
|
|
#include "progress-bar.hh"
|
2020-06-05 15:01:02 +00:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
LogFormat defaultLogFormat = LogFormat::raw;
|
|
|
|
|
2020-06-11 13:39:08 +00:00
|
|
|
LogFormat parseLogFormat(const std::string & logFormatStr) {
|
2020-06-05 15:01:02 +00:00
|
|
|
if (logFormatStr == "raw")
|
|
|
|
return LogFormat::raw;
|
2020-06-05 16:20:11 +00:00
|
|
|
else if (logFormatStr == "raw-with-logs")
|
|
|
|
return LogFormat::rawWithLogs;
|
2020-06-05 15:01:02 +00:00
|
|
|
else if (logFormatStr == "internal-json")
|
|
|
|
return LogFormat::internalJson;
|
|
|
|
else if (logFormatStr == "bar")
|
|
|
|
return LogFormat::bar;
|
|
|
|
else if (logFormatStr == "bar-with-logs")
|
|
|
|
return LogFormat::barWithLogs;
|
2020-06-08 11:24:01 +00:00
|
|
|
throw Error("option 'log-format' has an invalid value '%s'", logFormatStr);
|
2020-06-05 15:01:02 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 13:39:08 +00:00
|
|
|
Logger * makeDefaultLogger() {
|
2020-06-05 15:01:02 +00:00
|
|
|
switch (defaultLogFormat) {
|
|
|
|
case LogFormat::raw:
|
2020-06-29 16:20:51 +00:00
|
|
|
return makeSimpleLogger(false, false);
|
2020-06-05 16:20:11 +00:00
|
|
|
case LogFormat::rawWithLogs:
|
2020-06-29 16:20:51 +00:00
|
|
|
return makeSimpleLogger(true, false);
|
2020-06-05 15:01:02 +00:00
|
|
|
case LogFormat::internalJson:
|
2020-06-29 16:20:51 +00:00
|
|
|
return makeJSONLogger(*makeSimpleLogger(true, false));
|
2020-06-05 15:01:02 +00:00
|
|
|
case LogFormat::bar:
|
|
|
|
return makeProgressBar();
|
|
|
|
case LogFormat::barWithLogs:
|
|
|
|
return makeProgressBar(true);
|
2020-06-11 13:39:30 +00:00
|
|
|
default:
|
|
|
|
abort();
|
2020-06-05 15:01:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 13:39:08 +00:00
|
|
|
void setLogFormat(const std::string & logFormatStr) {
|
2020-06-05 15:01:02 +00:00
|
|
|
setLogFormat(parseLogFormat(logFormatStr));
|
|
|
|
}
|
|
|
|
|
2020-06-11 13:39:08 +00:00
|
|
|
void setLogFormat(const LogFormat & logFormat) {
|
2020-06-05 15:01:02 +00:00
|
|
|
defaultLogFormat = logFormat;
|
|
|
|
createDefaultLogger();
|
|
|
|
}
|
|
|
|
|
|
|
|
void createDefaultLogger() {
|
|
|
|
logger = makeDefaultLogger();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|