mirror of
https://github.com/NixOS/nix.git
synced 2025-04-16 06:08:03 +00:00
Merge pull request #12647 from DeterminateSystems/lock-json-logger
JSONLogger: Acquire a lock to prevent log messages from clobbering each other
This commit is contained in:
commit
e9af7a0749
@ -6,6 +6,7 @@
|
||||
#include "config-global.hh"
|
||||
#include "source-path.hh"
|
||||
#include "position.hh"
|
||||
#include "sync.hh"
|
||||
|
||||
#include <atomic>
|
||||
#include <sstream>
|
||||
@ -201,9 +202,22 @@ struct JSONLogger : Logger {
|
||||
unreachable();
|
||||
}
|
||||
|
||||
struct State
|
||||
{
|
||||
};
|
||||
|
||||
Sync<State> _state;
|
||||
|
||||
void write(const nlohmann::json & json)
|
||||
{
|
||||
writeLine(fd, "@nix " + json.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace));
|
||||
auto line =
|
||||
"@nix " +
|
||||
json.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace);
|
||||
|
||||
/* Acquire a lock to prevent log messages from clobbering each
|
||||
other. */
|
||||
auto state(_state.lock());
|
||||
writeLine(fd, line);
|
||||
}
|
||||
|
||||
void log(Verbosity lvl, std::string_view s) override
|
||||
|
Loading…
Reference in New Issue
Block a user