-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3073 from tweag/machine-logs
Add an option to print the logs in a machine-readable format
- Loading branch information
Showing
19 changed files
with
187 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include "types.hh" | ||
|
||
namespace nix { | ||
|
||
enum class LogFormat { | ||
raw, | ||
rawWithLogs, | ||
internalJson, | ||
bar, | ||
barWithLogs, | ||
}; | ||
|
||
void setLogFormat(const std::string & logFormatStr); | ||
void setLogFormat(const LogFormat & logFormat); | ||
|
||
void createDefaultLogger(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.