mirror of
https://github.com/NixOS/nix
synced 2025-07-07 06:01:48 +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:
parent
bc3a847784
commit
502f027390
3 changed files with 21 additions and 18 deletions
|
@ -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([&]() {
|
||||
|
|
|
@ -52,6 +52,14 @@ struct LoggerSettings : Config
|
|||
Whether Nix should print out a stack trace in case of Nix
|
||||
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;
|
||||
|
|
|
@ -348,21 +348,6 @@ struct CmdHelpStores : Command
|
|||
|
||||
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)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue