lix/src/libmain/loggers.cc

57 lines
1.5 KiB
C++
Raw Normal View History

#include "loggers.hh"
#include "progress-bar.hh"
2020-06-29 12:37:22 +00:00
#include "util.hh"
namespace nix {
LogFormat defaultLogFormat = LogFormat::raw;
2020-06-11 13:39:08 +00:00
LogFormat parseLogFormat(const std::string & logFormatStr) {
2020-06-29 12:37:22 +00:00
if (logFormatStr == "raw" || getEnv("NIX_GET_COMPLETIONS"))
return LogFormat::raw;
else if (logFormatStr == "raw-with-logs")
return LogFormat::rawWithLogs;
else if (logFormatStr == "internal-json")
2020-10-28 14:41:18 +00:00
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-11 13:39:08 +00:00
Logger * makeDefaultLogger() {
switch (defaultLogFormat) {
case LogFormat::raw:
return makeSimpleLogger(false);
case LogFormat::rawWithLogs:
return makeSimpleLogger(true);
2020-10-28 14:41:18 +00:00
case LogFormat::internalJSON:
2020-07-02 15:04:31 +00:00
return makeJSONLogger(*makeSimpleLogger(true));
case LogFormat::bar:
return makeProgressBar();
case LogFormat::barWithLogs: {
auto logger = makeProgressBar();
logger->setPrintBuildLogs(true);
return logger;
}
2020-06-11 13:39:30 +00:00
default:
abort();
}
}
2020-06-11 13:39:08 +00:00
void setLogFormat(const std::string & logFormatStr) {
setLogFormat(parseLogFormat(logFormatStr));
}
2020-06-11 13:39:08 +00:00
void setLogFormat(const LogFormat & logFormat) {
defaultLogFormat = logFormat;
createDefaultLogger();
}
void createDefaultLogger() {
logger = makeDefaultLogger();
}
}