diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc index b921dbe2d..13655f6a8 100644 --- a/src/libstore/daemon.cc +++ b/src/libstore/daemon.cc @@ -15,6 +15,7 @@ #include "derivations.hh" #include "args.hh" #include "git.hh" +#include "logging.hh" #ifndef _WIN32 // TODO need graceful async exit support on Windows? # include "monitor-fd.hh" @@ -1044,9 +1045,18 @@ void processConnection( auto tunnelLogger = new TunnelLogger(conn.to, protoVersion); auto prevLogger = nix::logger; // FIXME - if (!recursive) + if (!recursive) { 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; Finally finally([&]() { diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index aeb058526..479459e9f 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -52,6 +52,14 @@ struct LoggerSettings : Config Whether Nix should print out a stack trace in case of Nix expression evaluation errors. )"}; + + Setting 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; diff --git a/src/nix/main.cc b/src/nix/main.cc index 644c65cf0..cad561c66 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -348,21 +348,6 @@ struct CmdHelpStores : Command static auto rCmdHelpStores = registerCommand("help-stores"); -struct ExtLoggerSettings : Config -{ - Setting 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) { savedArgv = argv; @@ -501,9 +486,9 @@ void mainWrapped(int argc, char * * argv) if (!args.helpRequested && !args.completions) throw; } - if (!extLoggerSettings.jsonLogPath.get().empty()) { + if (!loggerSettings.jsonLogPath.get().empty()) { try { - logger = makeTeeLogger({logger, makeJSONLogger(std::filesystem::path(extLoggerSettings.jsonLogPath.get()), false)}); + logger = makeTeeLogger({logger, makeJSONLogger(std::filesystem::path(loggerSettings.jsonLogPath.get()), false)}); } catch (...) { ignoreExceptionExceptInterrupt(); }