mirror of
https://github.com/NixOS/nix
synced 2025-06-28 22:01:15 +02:00
Make the JSON logger more robust
We now ignore connection / write errors.
This commit is contained in:
parent
fd0d824fa5
commit
8674792eba
2 changed files with 18 additions and 3 deletions
|
@ -196,6 +196,7 @@ struct JSONLogger : Logger {
|
||||||
|
|
||||||
struct State
|
struct State
|
||||||
{
|
{
|
||||||
|
bool enabled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
Sync<State> _state;
|
Sync<State> _state;
|
||||||
|
@ -208,8 +209,18 @@ struct JSONLogger : Logger {
|
||||||
|
|
||||||
/* Acquire a lock to prevent log messages from clobbering each
|
/* Acquire a lock to prevent log messages from clobbering each
|
||||||
other. */
|
other. */
|
||||||
|
try {
|
||||||
auto state(_state.lock());
|
auto state(_state.lock());
|
||||||
|
if (state->enabled)
|
||||||
writeLine(fd, line);
|
writeLine(fd, line);
|
||||||
|
} catch (...) {
|
||||||
|
bool enabled = false;
|
||||||
|
std::swap(_state.lock()->enabled, enabled);
|
||||||
|
if (enabled) {
|
||||||
|
ignoreExceptionExceptInterrupt();
|
||||||
|
logger->warn("disabling JSON logger due to write errors");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void log(Verbosity lvl, std::string_view s) override
|
void log(Verbosity lvl, std::string_view s) override
|
||||||
|
|
|
@ -502,7 +502,11 @@ void mainWrapped(int argc, char * * argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!extLoggerSettings.jsonLogPath.get().empty()) {
|
if (!extLoggerSettings.jsonLogPath.get().empty()) {
|
||||||
|
try {
|
||||||
logger = makeTeeLogger({logger, makeJSONLogger(std::filesystem::path(extLoggerSettings.jsonLogPath.get()), false)});
|
logger = makeTeeLogger({logger, makeJSONLogger(std::filesystem::path(extLoggerSettings.jsonLogPath.get()), false)});
|
||||||
|
} catch (...) {
|
||||||
|
ignoreExceptionExceptInterrupt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.helpRequested) {
|
if (args.helpRequested) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue