-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add json-log-path
setting
#13003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
edolstra
wants to merge
2
commits into
NixOS:master
Choose a base branch
from
DeterminateSystems:json-log-path
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+228
−10
Open
Add json-log-path
setting
#13003
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
synopsis: "`json-log-path` setting" | ||
prs: [13003] | ||
--- | ||
|
||
New setting `json-log-path` that sends a copy of all Nix log messages (in JSON format) to a file or Unix domain socket. |
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 | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -6,6 +6,8 @@ | |||||||
#include "nix/util/file-descriptor.hh" | ||||||||
#include "nix/util/finally.hh" | ||||||||
|
||||||||
#include <filesystem> | ||||||||
|
||||||||
#include <nlohmann/json_fwd.hpp> | ||||||||
|
||||||||
namespace nix { | ||||||||
|
@@ -49,6 +51,14 @@ struct LoggerSettings : Config | |||||||
Whether Nix should print out a stack trace in case of Nix | ||||||||
expression evaluation errors. | ||||||||
)"}; | ||||||||
|
||||||||
Setting<Path> jsonLogPath{ | ||||||||
this, "", "json-log-path", | ||||||||
R"( | ||||||||
A path to which JSON records of Nix's log output will be | ||||||||
written, in the same format as `--log-format internal-json` | ||||||||
(without the `@nix ` prefixes on each line). | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional as suggested by the reviewer:
Suggested change
|
||||||||
)"}; | ||||||||
}; | ||||||||
|
||||||||
extern LoggerSettings loggerSettings; | ||||||||
|
@@ -196,7 +206,20 @@ extern std::unique_ptr<Logger> logger; | |||||||
|
||||||||
std::unique_ptr<Logger> makeSimpleLogger(bool printBuildLogs = true); | ||||||||
|
||||||||
std::unique_ptr<Logger> makeJSONLogger(Descriptor fd); | ||||||||
/** | ||||||||
* Create a logger that sends log messages to `mainLogger` and the | ||||||||
* list of loggers in `extraLoggers`. Only `mainLogger` is used for | ||||||||
* writing to stdout and getting user input. | ||||||||
*/ | ||||||||
std::unique_ptr<Logger> makeTeeLogger( | ||||||||
std::unique_ptr<Logger> mainLogger, | ||||||||
std::vector<std::unique_ptr<Logger>> && extraLoggers); | ||||||||
|
||||||||
std::unique_ptr<Logger> makeJSONLogger(Descriptor fd, bool includeNixPrefix = true); | ||||||||
|
||||||||
std::unique_ptr<Logger> makeJSONLogger(const std::filesystem::path & path, bool includeNixPrefix = true); | ||||||||
|
||||||||
void applyJSONLogger(); | ||||||||
|
||||||||
/** | ||||||||
* @param source A noun phrase describing the source of the message, e.g. "the builder". | ||||||||
|
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,107 @@ | ||
#include "nix/util/logging.hh" | ||
|
||
namespace nix { | ||
|
||
struct TeeLogger : Logger | ||
{ | ||
std::vector<std::unique_ptr<Logger>> loggers; | ||
|
||
TeeLogger(std::vector<std::unique_ptr<Logger>> && loggers) | ||
: loggers(std::move(loggers)) | ||
{ | ||
} | ||
|
||
void stop() override | ||
{ | ||
for (auto & logger : loggers) | ||
logger->stop(); | ||
}; | ||
|
||
void pause() override | ||
{ | ||
for (auto & logger : loggers) | ||
logger->pause(); | ||
}; | ||
|
||
void resume() override | ||
{ | ||
for (auto & logger : loggers) | ||
logger->resume(); | ||
}; | ||
|
||
void log(Verbosity lvl, std::string_view s) override | ||
{ | ||
for (auto & logger : loggers) | ||
logger->log(lvl, s); | ||
} | ||
|
||
void logEI(const ErrorInfo & ei) override | ||
{ | ||
for (auto & logger : loggers) | ||
logger->logEI(ei); | ||
} | ||
|
||
void startActivity( | ||
ActivityId act, | ||
Verbosity lvl, | ||
ActivityType type, | ||
const std::string & s, | ||
const Fields & fields, | ||
ActivityId parent) override | ||
{ | ||
for (auto & logger : loggers) | ||
logger->startActivity(act, lvl, type, s, fields, parent); | ||
} | ||
|
||
void stopActivity(ActivityId act) override | ||
{ | ||
for (auto & logger : loggers) | ||
logger->stopActivity(act); | ||
} | ||
|
||
void result(ActivityId act, ResultType type, const Fields & fields) override | ||
{ | ||
for (auto & logger : loggers) | ||
logger->result(act, type, fields); | ||
} | ||
|
||
void writeToStdout(std::string_view s) override | ||
{ | ||
for (auto & logger : loggers) { | ||
/* Let only the first logger write to stdout to avoid | ||
duplication. This means that the first logger needs to | ||
be the one managing stdout/stderr | ||
(e.g. `ProgressBar`). */ | ||
logger->writeToStdout(s); | ||
break; | ||
} | ||
} | ||
|
||
std::optional<char> ask(std::string_view s) override | ||
{ | ||
for (auto & logger : loggers) { | ||
auto c = logger->ask(s); | ||
if (c) | ||
return c; | ||
} | ||
return std::nullopt; | ||
} | ||
|
||
void setPrintBuildLogs(bool printBuildLogs) override | ||
{ | ||
for (auto & logger : loggers) | ||
logger->setPrintBuildLogs(printBuildLogs); | ||
} | ||
}; | ||
|
||
std::unique_ptr<Logger> | ||
makeTeeLogger(std::unique_ptr<Logger> mainLogger, std::vector<std::unique_ptr<Logger>> && extraLoggers) | ||
{ | ||
std::vector<std::unique_ptr<Logger>> allLoggers; | ||
allLoggers.push_back(std::move(mainLogger)); | ||
for (auto & l : extraLoggers) | ||
allLoggers.push_back(std::move(l)); | ||
return std::make_unique<TeeLogger>(std::move(allLoggers)); | ||
} | ||
|
||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.