1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-30 19:57:59 +02:00

makeJSONLogger(): Support logging to a Unix domain socket

This commit is contained in:
Eelco Dolstra 2025-03-13 15:48:52 +01:00
parent d9730fc93b
commit 220000dc1a
4 changed files with 18 additions and 4 deletions

View file

@ -7,6 +7,7 @@
#include "source-path.hh"
#include "position.hh"
#include "sync.hh"
#include "unix-domain-socket.hh"
#include <atomic>
#include <sstream>
@ -296,7 +297,10 @@ Logger * makeJSONLogger(const std::filesystem::path & path, bool includeNixPrefi
{ }
};
AutoCloseFD fd{toDescriptor(open(path.c_str(), O_CREAT | O_APPEND | O_WRONLY, 0644))};
AutoCloseFD fd =
std::filesystem::is_socket(path)
? connect(path)
: toDescriptor(open(path.c_str(), O_CREAT | O_APPEND | O_WRONLY, 0644));
if (!fd)
throw SysError("opening log file '%1%'", path);