From 2972e7394606650ed2ed4669ea79581817294a72 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 13 Mar 2025 13:15:14 +0100 Subject: [PATCH] Turn NIX_LOG_FILE into a setting --- src/nix/main.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/nix/main.cc b/src/nix/main.cc index 5f83e997c..10a02fe3f 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -5,6 +5,7 @@ #include "eval.hh" #include "eval-settings.hh" #include "globals.hh" +#include "config-global.hh" #include "legacy.hh" #include "shared.hh" #include "store-api.hh" @@ -347,6 +348,20 @@ 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`. + )"}; +}; + +static ExtLoggerSettings extLoggerSettings; + +static GlobalConfig::Register rExtLoggerSettings(&extLoggerSettings); + void mainWrapped(int argc, char * * argv) { savedArgv = argv; @@ -485,8 +500,8 @@ void mainWrapped(int argc, char * * argv) if (!args.helpRequested && !args.completions) throw; } - if (auto logFile = getEnv("NIX_LOG_FILE")) { - logger = makeTeeLogger({logger, makeJSONLogger(*logFile)}); + if (!extLoggerSettings.jsonLogPath.get().empty()) { + logger = makeTeeLogger({logger, makeJSONLogger(std::filesystem::path(extLoggerSettings.jsonLogPath.get()))}); } if (args.helpRequested) {