mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-01-20 10:06:47 +02:00
ac89bb064a
All OS and IO operations should be moved out, leaving only some misc portable pure functions. This is useful to avoid copious CPP when doing things like Windows and Emscripten ports. Newly exposed functions to break cycles: - `restoreSignals` - `updateWindowSize`
56 lines
1.5 KiB
C++
56 lines
1.5 KiB
C++
#include "loggers.hh"
|
|
#include "environment-variables.hh"
|
|
#include "progress-bar.hh"
|
|
|
|
namespace nix {
|
|
|
|
LogFormat defaultLogFormat = LogFormat::raw;
|
|
|
|
LogFormat parseLogFormat(const std::string & logFormatStr) {
|
|
if (logFormatStr == "raw" || getEnv("NIX_GET_COMPLETIONS"))
|
|
return LogFormat::raw;
|
|
else if (logFormatStr == "raw-with-logs")
|
|
return LogFormat::rawWithLogs;
|
|
else if (logFormatStr == "internal-json")
|
|
return LogFormat::internalJSON;
|
|
else if (logFormatStr == "bar")
|
|
return LogFormat::bar;
|
|
else if (logFormatStr == "bar-with-logs")
|
|
return LogFormat::barWithLogs;
|
|
throw Error("option 'log-format' has an invalid value '%s'", logFormatStr);
|
|
}
|
|
|
|
Logger * makeDefaultLogger() {
|
|
switch (defaultLogFormat) {
|
|
case LogFormat::raw:
|
|
return makeSimpleLogger(false);
|
|
case LogFormat::rawWithLogs:
|
|
return makeSimpleLogger(true);
|
|
case LogFormat::internalJSON:
|
|
return makeJSONLogger(*makeSimpleLogger(true));
|
|
case LogFormat::bar:
|
|
return makeProgressBar();
|
|
case LogFormat::barWithLogs: {
|
|
auto logger = makeProgressBar();
|
|
logger->setPrintBuildLogs(true);
|
|
return logger;
|
|
}
|
|
default:
|
|
abort();
|
|
}
|
|
}
|
|
|
|
void setLogFormat(const std::string & logFormatStr) {
|
|
setLogFormat(parseLogFormat(logFormatStr));
|
|
}
|
|
|
|
void setLogFormat(const LogFormat & logFormat) {
|
|
defaultLogFormat = logFormat;
|
|
createDefaultLogger();
|
|
}
|
|
|
|
void createDefaultLogger() {
|
|
logger = makeDefaultLogger();
|
|
}
|
|
|
|
}
|