1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-24 22:11:15 +02:00

Merge pull request #13249 from NixOS/more-robust-json-logger

Make the JSON logger more robust
This commit is contained in:
Jörg Thalheim 2025-05-23 10:25:16 +02:00 committed by GitHub
commit 5b4806ab3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -204,6 +204,7 @@ struct JSONLogger : Logger {
struct State
{
bool enabled = true;
};
Sync<State> _state;
@ -216,8 +217,18 @@ struct JSONLogger : Logger {
/* Acquire a lock to prevent log messages from clobbering each
other. */
auto state(_state.lock());
writeLine(fd, line);
try {
auto state(_state.lock());
if (state->enabled)
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