mirror of
https://github.com/NixOS/nix
synced 2025-06-29 02:11:15 +02:00
Make the JSON logger more robust
We now ignore connection / write errors.
This commit is contained in:
parent
b4bea57667
commit
9f680874c5
1 changed files with 13 additions and 2 deletions
|
@ -204,6 +204,7 @@ struct JSONLogger : Logger {
|
||||||
|
|
||||||
struct State
|
struct State
|
||||||
{
|
{
|
||||||
|
bool enabled = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
Sync<State> _state;
|
Sync<State> _state;
|
||||||
|
@ -216,8 +217,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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue