1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 18:31:49 +02:00

Turn NIX_LOG_FILE into a setting

This commit is contained in:
Eelco Dolstra 2025-03-13 13:15:14 +01:00
parent 1f702cdb01
commit 2972e73946

View file

@ -5,6 +5,7 @@
#include "eval.hh" #include "eval.hh"
#include "eval-settings.hh" #include "eval-settings.hh"
#include "globals.hh" #include "globals.hh"
#include "config-global.hh"
#include "legacy.hh" #include "legacy.hh"
#include "shared.hh" #include "shared.hh"
#include "store-api.hh" #include "store-api.hh"
@ -347,6 +348,20 @@ 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`.
)"};
};
static ExtLoggerSettings extLoggerSettings;
static GlobalConfig::Register rExtLoggerSettings(&extLoggerSettings);
void mainWrapped(int argc, char * * argv) void mainWrapped(int argc, char * * argv)
{ {
savedArgv = argv; savedArgv = argv;
@ -485,8 +500,8 @@ void mainWrapped(int argc, char * * argv)
if (!args.helpRequested && !args.completions) throw; if (!args.helpRequested && !args.completions) throw;
} }
if (auto logFile = getEnv("NIX_LOG_FILE")) { if (!extLoggerSettings.jsonLogPath.get().empty()) {
logger = makeTeeLogger({logger, makeJSONLogger(*logFile)}); logger = makeTeeLogger({logger, makeJSONLogger(std::filesystem::path(extLoggerSettings.jsonLogPath.get()))});
} }
if (args.helpRequested) { if (args.helpRequested) {