mirror of
https://github.com/NixOS/nix
synced 2025-07-01 08:28:00 +02:00
JSONLogger: Acquire a lock to prevent log messages from clobbering each other
This commit is contained in:
parent
29a9e638c1
commit
1efccf34b1
1 changed files with 14 additions and 2 deletions
|
@ -6,6 +6,7 @@
|
||||||
#include "config-global.hh"
|
#include "config-global.hh"
|
||||||
#include "source-path.hh"
|
#include "source-path.hh"
|
||||||
#include "position.hh"
|
#include "position.hh"
|
||||||
|
#include "sync.hh"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -192,11 +193,22 @@ struct JSONLogger : Logger {
|
||||||
unreachable();
|
unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct State
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
Sync<State> _state;
|
||||||
|
|
||||||
void write(const nlohmann::json & json)
|
void write(const nlohmann::json & json)
|
||||||
{
|
{
|
||||||
writeLine(fd,
|
auto line =
|
||||||
(includeNixPrefix ? "@nix " : "") +
|
(includeNixPrefix ? "@nix " : "") +
|
||||||
json.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace));
|
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
|
void log(Verbosity lvl, std::string_view s) override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue