diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2020-06-18 21:38:15 +0000 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2020-06-18 21:38:15 +0000 |
commit | 40526fbea56a8006eb7f1758d461a5acbe9a1694 (patch) | |
tree | 5d74492a86f28fb7183897dc2a6d7baf2d24f7f1 /src/libmain/loggers.cc | |
parent | 6dd471ebf6b9a4996405398093ccb371b8abdf2f (diff) | |
parent | 6c000eed80565d83d596da800ca0db92e248342e (diff) |
Merge remote-tracking branch 'upstream/master' into enum-class
Diffstat (limited to 'src/libmain/loggers.cc')
-rw-r--r-- | src/libmain/loggers.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/libmain/loggers.cc b/src/libmain/loggers.cc new file mode 100644 index 000000000..c44bb6408 --- /dev/null +++ b/src/libmain/loggers.cc @@ -0,0 +1,52 @@ +#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; + 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()); + case LogFormat::bar: + return makeProgressBar(); + case LogFormat::barWithLogs: + return makeProgressBar(true); + default: + abort(); + } +} + +void setLogFormat(const std::string & logFormatStr) { + setLogFormat(parseLogFormat(logFormatStr)); +} + +void setLogFormat(const LogFormat & logFormat) { + defaultLogFormat = logFormat; + createDefaultLogger(); +} + +void createDefaultLogger() { + logger = makeDefaultLogger(); +} + +} |