alois31
82aa1ccab4
When generating shell completions, no logging output should be visible because it would destroy the shell prompt. Originally this was attempted to be done by simply disabling the progress bar (ca946860ce
), since the situation is particularly bad there (the screen clearing required for the rendering ends up erasing the shell prompt). Due to overlooking the implementation of this hack, it was accidentally undone during a later change (0dd1d8ca1c
). Since even with the hack correctly in place, it is still possible to mess up the prompt by logging output (for example warnings for disabled experimental features, or messages generated by `builtins.trace`), simply send it to the bit bucket where it belongs. This was already done for bash and zsh (9d840758a8
), and it seems that fish was simply missed at that time. The last trace of the no-longer-working and obsolete hack is deleted too. Fixes: #513 Change-Id:I59f1ebf90903034e2059298fa8d76bf970bc3315
72 lines
2 KiB
C++
72 lines
2 KiB
C++
#include "environment-variables.hh"
|
|
#include "loggers.hh"
|
|
#include "progress-bar.hh"
|
|
|
|
namespace nix {
|
|
|
|
LogFormat defaultLogFormat = LogFormat::raw;
|
|
|
|
LogFormat parseLogFormat(const std::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;
|
|
else if (logFormatStr == "multiline")
|
|
return LogFormat::multiline;
|
|
else if (logFormatStr == "multiline-with-logs")
|
|
return LogFormat::multilineWithLogs;
|
|
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;
|
|
}
|
|
case LogFormat::multiline: {
|
|
auto logger = makeProgressBar();
|
|
logger->setPrintMultiline(true);
|
|
return logger;
|
|
}
|
|
case LogFormat::multilineWithLogs: {
|
|
auto logger = makeProgressBar();
|
|
logger->setPrintMultiline(true);
|
|
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();
|
|
}
|
|
|
|
}
|