1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 10:11:47 +02:00

nix daemon: Respect json-log-path and re-open for every connection

We don't want to inherit the parent's JSON logger since then messages
from different daemon processes may clobber each other.
This commit is contained in:
Eelco Dolstra 2025-03-26 22:15:39 +01:00
parent bc3a847784
commit 502f027390
3 changed files with 21 additions and 18 deletions

View file

@ -15,6 +15,7 @@
#include "derivations.hh" #include "derivations.hh"
#include "args.hh" #include "args.hh"
#include "git.hh" #include "git.hh"
#include "logging.hh"
#ifndef _WIN32 // TODO need graceful async exit support on Windows? #ifndef _WIN32 // TODO need graceful async exit support on Windows?
# include "monitor-fd.hh" # include "monitor-fd.hh"
@ -1044,9 +1045,18 @@ void processConnection(
auto tunnelLogger = new TunnelLogger(conn.to, protoVersion); auto tunnelLogger = new TunnelLogger(conn.to, protoVersion);
auto prevLogger = nix::logger; auto prevLogger = nix::logger;
// FIXME // FIXME
if (!recursive) if (!recursive) {
logger = tunnelLogger; logger = tunnelLogger;
if (!loggerSettings.jsonLogPath.get().empty()) {
try {
logger = makeTeeLogger({logger, makeJSONLogger(std::filesystem::path(loggerSettings.jsonLogPath.get()), false)});
} catch (...) {
ignoreExceptionExceptInterrupt();
}
}
}
unsigned int opCount = 0; unsigned int opCount = 0;
Finally finally([&]() { Finally finally([&]() {

View file

@ -52,6 +52,14 @@ struct LoggerSettings : Config
Whether Nix should print out a stack trace in case of Nix Whether Nix should print out a stack trace in case of Nix
expression evaluation errors. expression evaluation errors.
)"}; )"};
Setting<Path> jsonLogPath{
this, "", "json-log-path",
R"(
A path to which JSON records of Nix's log output will be
written, in the same format as `--log-format internal-json`
(without the `@nix ` prefixes on each line).
)"};
}; };
extern LoggerSettings loggerSettings; extern LoggerSettings loggerSettings;

View file

@ -348,21 +348,6 @@ struct CmdHelpStores : Command
static auto rCmdHelpStores = registerCommand<CmdHelpStores>("help-stores"); static auto rCmdHelpStores = registerCommand<CmdHelpStores>("help-stores");
struct ExtLoggerSettings : Config
{
Setting<Path> jsonLogPath{
this, "", "json-log-path",
R"(
A path to which JSON records of Nix's log output will be
written, in the same format as `--log-format internal-json`
(without the `@nix ` prefixes on each line).
)"};
};
static ExtLoggerSettings extLoggerSettings;
static GlobalConfig::Register rExtLoggerSettings(&extLoggerSettings);
void mainWrapped(int argc, char * * argv) void mainWrapped(int argc, char * * argv)
{ {
savedArgv = argv; savedArgv = argv;
@ -501,9 +486,9 @@ void mainWrapped(int argc, char * * argv)
if (!args.helpRequested && !args.completions) throw; if (!args.helpRequested && !args.completions) throw;
} }
if (!extLoggerSettings.jsonLogPath.get().empty()) { if (!loggerSettings.jsonLogPath.get().empty()) {
try { try {
logger = makeTeeLogger({logger, makeJSONLogger(std::filesystem::path(extLoggerSettings.jsonLogPath.get()), false)}); logger = makeTeeLogger({logger, makeJSONLogger(std::filesystem::path(loggerSettings.jsonLogPath.get()), false)});
} catch (...) { } catch (...) {
ignoreExceptionExceptInterrupt(); ignoreExceptionExceptInterrupt();
} }