diff --git a/src/libmain/loggers.cc b/src/libmain/loggers.cc index cdf23859b..b450b944a 100644 --- a/src/libmain/loggers.cc +++ b/src/libmain/loggers.cc @@ -15,8 +15,6 @@ LogFormat parseLogFormat(const std::string & logFormatStr) { 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); } @@ -30,8 +28,6 @@ Logger * makeDefaultLogger() { return makeJSONLogger(*makeSimpleLogger(true)); case LogFormat::bar: return makeProgressBar(); - case LogFormat::barWithLogs: - return makeProgressBar(true); default: abort(); } diff --git a/src/libmain/loggers.hh b/src/libmain/loggers.hh index f3c759193..127d6068c 100644 --- a/src/libmain/loggers.hh +++ b/src/libmain/loggers.hh @@ -9,7 +9,6 @@ enum class LogFormat { rawWithLogs, internalJSON, bar, - barWithLogs, }; void setLogFormat(const std::string & logFormatStr); diff --git a/src/libmain/progress-bar.cc b/src/libmain/progress-bar.cc index 7a984ea6a..305345615 100644 --- a/src/libmain/progress-bar.cc +++ b/src/libmain/progress-bar.cc @@ -15,6 +15,10 @@ namespace nix { +ProgressBarSettings progressBarSettings; + +static GlobalConfig::Register rProgressBarSettings(&progressBarSettings); + static std::string getS(const std::vector & fields, size_t n) { assert(n < fields.size()); @@ -133,8 +137,6 @@ private: bool active = true; bool haveUpdate = true; - bool printBuildLogs; - std::map statusLines; /* How many lines need to be erased when redrawing. */ @@ -158,9 +160,9 @@ private: public: - ProgressBar(bool printBuildLogs, bool isTTY) + ProgressBar(bool isTTY) : isTTY(isTTY) - , state_({ .active = isTTY, .printBuildLogs = printBuildLogs }) + , state_({ .active = isTTY }) { state_.lock()->active = isTTY; @@ -224,10 +226,10 @@ public: } if (c == 'l') { auto state(state_.lock()); - state->printBuildLogs = !state->printBuildLogs; + progressBarSettings.printBuildLogs = !progressBarSettings.printBuildLogs; updateStatusLine(*state); draw(*state, - state->printBuildLogs + progressBarSettings.printBuildLogs ? ANSI_BOLD "Enabling build logs." : ANSI_BOLD "Disabling build logs."); } @@ -298,7 +300,7 @@ public: bool isVerbose() override { - return state_.lock()->printBuildLogs; + return progressBarSettings.printBuildLogs; } void log(Verbosity lvl, const FormatOrString & fs) override @@ -470,7 +472,7 @@ public: auto i = state->its.find(act); assert(i != state->its.end()); i->second->lastLine = lastLine; - if (state->printBuildLogs) { + if (progressBarSettings.printBuildLogs) { auto suffix = "> "; if (type == resPostBuildLogLine) { suffix = " (post)> "; @@ -720,10 +722,9 @@ public: } }; -Logger * makeProgressBar(bool printBuildLogs) +Logger * makeProgressBar() { return new ProgressBar( - printBuildLogs, isatty(STDIN_FILENO) && isatty(STDOUT_FILENO) && isatty(STDERR_FILENO) @@ -731,11 +732,6 @@ Logger * makeProgressBar(bool printBuildLogs) ); } -void startProgressBar(bool printBuildLogs) -{ - logger = makeProgressBar(printBuildLogs); -} - void stopProgressBar() { auto progressBar = dynamic_cast(logger); diff --git a/src/libmain/progress-bar.hh b/src/libmain/progress-bar.hh index 7f0dafecf..5227b3e03 100644 --- a/src/libmain/progress-bar.hh +++ b/src/libmain/progress-bar.hh @@ -4,10 +4,16 @@ namespace nix { -Logger * makeProgressBar(bool printBuildLogs = false); - -void startProgressBar(bool printBuildLogs = false); +Logger * makeProgressBar(); void stopProgressBar(); +struct ProgressBarSettings : Config +{ + Setting printBuildLogs{this, false, "print-build-logs", + "Whether the progress bar should print full build logs or just the most recent line."}; +}; + +extern ProgressBarSettings progressBarSettings; + } diff --git a/src/nix-prefetch-url/nix-prefetch-url.cc b/src/nix-prefetch-url/nix-prefetch-url.cc index 3bdee55a7..055ab1a81 100644 --- a/src/nix-prefetch-url/nix-prefetch-url.cc +++ b/src/nix-prefetch-url/nix-prefetch-url.cc @@ -10,6 +10,7 @@ #include "../nix/legacy.hh" #include "progress-bar.hh" #include "tarfile.hh" +#include "loggers.hh" #include @@ -103,7 +104,7 @@ static int main_nix_prefetch_url(int argc, char * * argv) Finally f([]() { stopProgressBar(); }); if (isatty(STDERR_FILENO)) - startProgressBar(); + setLogFormat(LogFormat::bar); auto store = openStore(); auto state = std::make_unique(myArgs.searchPath, store); diff --git a/src/nix/main.cc b/src/nix/main.cc index c3d32083b..3442e7c77 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -10,6 +10,7 @@ #include "filetransfer.hh" #include "finally.hh" #include "loggers.hh" +#include "progress-bar.hh" #include #include @@ -55,7 +56,6 @@ std::string programPath; struct NixArgs : virtual MultiCommand, virtual MixCommonArgs { - bool printBuildLogs = false; bool useNet = true; bool refresh = false; @@ -88,12 +88,11 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs }}, }); - // FIXME: make this a setting, remove LogFormat::barWithLogs. addFlag({ .longName = "print-build-logs", .shortName = 'L', .description = "print full build logs on stderr", - .handler = {[&]() { printBuildLogs = true; }}, + .handler = {[&]() { progressBarSettings.printBuildLogs = true; }}, }); addFlag({ @@ -298,7 +297,7 @@ void mainWrapped(int argc, char * * argv) if (completions) return; - setLogFormat(args.printBuildLogs ? LogFormat::bar : LogFormat::barWithLogs); + setLogFormat(LogFormat::bar); Finally f([] { logger->stop(); });