forked from lix-project/lix
4983401440
Make the printing of the build logs systematically go through the logger, and replicate the behavior of `no-build-output` by having two different loggers (one that prints the build logs and one that doesn't)
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#include "loggers.hh"
|
|
#include "../nix/progress-bar.hh"
|
|
|
|
namespace nix {
|
|
|
|
LogFormat defaultLogFormat = LogFormat::raw;
|
|
|
|
LogFormat parseLogFormat(const string &logFormatStr) {
|
|
if (logFormatStr == "raw")
|
|
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(format("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());
|
|
case LogFormat::bar:
|
|
return makeProgressBar();
|
|
case LogFormat::barWithLogs:
|
|
return makeProgressBar(true);
|
|
}
|
|
}
|
|
|
|
void setLogFormat(const string &logFormatStr) {
|
|
setLogFormat(parseLogFormat(logFormatStr));
|
|
}
|
|
|
|
void setLogFormat(const LogFormat &logFormat) {
|
|
defaultLogFormat = logFormat;
|
|
createDefaultLogger();
|
|
}
|
|
|
|
void createDefaultLogger() {
|
|
logger = makeDefaultLogger();
|
|
}
|
|
|
|
}
|