2020-06-05 18:01:02 +03:00
|
|
|
#include "loggers.hh"
|
2020-06-08 18:16:52 +03:00
|
|
|
#include "progress-bar.hh"
|
2020-06-29 15:37:22 +03:00
|
|
|
#include "util.hh"
|
2020-06-05 18:01:02 +03:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
LogFormat defaultLogFormat = LogFormat::raw;
|
|
|
|
|
2020-06-11 16:39:08 +03:00
|
|
|
LogFormat parseLogFormat(const std::string & logFormatStr) {
|
2020-06-29 15:37:22 +03:00
|
|
|
if (logFormatStr == "raw" || getEnv("NIX_GET_COMPLETIONS"))
|
2020-06-05 18:01:02 +03:00
|
|
|
return LogFormat::raw;
|
2020-06-05 19:20:11 +03:00
|
|
|
else if (logFormatStr == "raw-with-logs")
|
|
|
|
return LogFormat::rawWithLogs;
|
2020-06-05 18:01:02 +03:00
|
|
|
else if (logFormatStr == "internal-json")
|
2020-10-28 16:41:18 +02:00
|
|
|
return LogFormat::internalJSON;
|
2020-06-05 18:01:02 +03:00
|
|
|
else if (logFormatStr == "bar")
|
|
|
|
return LogFormat::bar;
|
|
|
|
else if (logFormatStr == "bar-with-logs")
|
|
|
|
return LogFormat::barWithLogs;
|
2020-06-08 14:24:01 +03:00
|
|
|
throw Error("option 'log-format' has an invalid value '%s'", logFormatStr);
|
2020-06-05 18:01:02 +03:00
|
|
|
}
|
|
|
|
|
2020-06-11 16:39:08 +03:00
|
|
|
Logger * makeDefaultLogger() {
|
2020-06-05 18:01:02 +03:00
|
|
|
switch (defaultLogFormat) {
|
|
|
|
case LogFormat::raw:
|
2020-06-05 19:20:11 +03:00
|
|
|
return makeSimpleLogger(false);
|
|
|
|
case LogFormat::rawWithLogs:
|
|
|
|
return makeSimpleLogger(true);
|
2020-10-28 16:41:18 +02:00
|
|
|
case LogFormat::internalJSON:
|
2020-07-02 18:04:31 +03:00
|
|
|
return makeJSONLogger(*makeSimpleLogger(true));
|
2020-06-05 18:01:02 +03:00
|
|
|
case LogFormat::bar:
|
|
|
|
return makeProgressBar();
|
2022-08-24 23:36:40 +03:00
|
|
|
case LogFormat::barWithLogs: {
|
|
|
|
auto logger = makeProgressBar();
|
|
|
|
logger->setPrintBuildLogs(true);
|
|
|
|
return logger;
|
|
|
|
}
|
2020-06-11 16:39:30 +03:00
|
|
|
default:
|
|
|
|
abort();
|
2020-06-05 18:01:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 16:39:08 +03:00
|
|
|
void setLogFormat(const std::string & logFormatStr) {
|
2020-06-05 18:01:02 +03:00
|
|
|
setLogFormat(parseLogFormat(logFormatStr));
|
|
|
|
}
|
|
|
|
|
2020-06-11 16:39:08 +03:00
|
|
|
void setLogFormat(const LogFormat & logFormat) {
|
2020-06-05 18:01:02 +03:00
|
|
|
defaultLogFormat = logFormat;
|
|
|
|
createDefaultLogger();
|
|
|
|
}
|
|
|
|
|
|
|
|
void createDefaultLogger() {
|
|
|
|
logger = makeDefaultLogger();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|