diff --git a/go/cmd/entrypoint/daemon.go b/go/cmd/entrypoint/daemon.go index afc85e7..f455fef 100644 --- a/go/cmd/entrypoint/daemon.go +++ b/go/cmd/entrypoint/daemon.go @@ -42,7 +42,7 @@ var subCmdDaemon = subCmd{ networkLoader, err := network.NewLoader( ctx, - ctx.logger.WithNamespace("loader"), + ctx.logger.WithNamespace("network-loader"), envBinDirPath, nil, ) @@ -50,18 +50,22 @@ var subCmdDaemon = subCmd{ return fmt.Errorf("instantiating network loader: %w", err) } + daemonLogger := ctx.logger.WithNamespace("daemon") daemonInst, err := daemon.New( - ctx, ctx.logger, networkLoader, daemonConfig, + ctx, + daemonLogger, + networkLoader, + daemonConfig, ) if err != nil { return fmt.Errorf("starting daemon: %w", err) } defer func() { - ctx.logger.Info(ctx, "Stopping child processes") + daemonLogger.Info(ctx, "Stopping daemon") if err := daemonInst.Shutdown(); err != nil { ctx.logger.Error(ctx, "Shutting down daemon cleanly failed, there may be orphaned child processes", err) } - ctx.logger.Info(ctx, "Child processes successfully stopped") + daemonLogger.Info(ctx, "Daemon successfully stopped") }() { diff --git a/go/daemon/daemon.go b/go/daemon/daemon.go index 3c8996e..d3b399f 100644 --- a/go/daemon/daemon.go +++ b/go/daemon/daemon.go @@ -13,7 +13,6 @@ import ( "sort" "sync" - "dev.mediocregopher.com/mediocre-go-lib.git/mctx" "dev.mediocregopher.com/mediocre-go-lib.git/mlog" ) @@ -71,8 +70,6 @@ func New( } for _, creationParams := range loadableNetworks { - ctx = mctx.WithAnnotator(ctx, creationParams) - var ( id = creationParams.ID networkConfig = pickNetworkConfig(daemonConfig, creationParams) @@ -80,7 +77,7 @@ func New( n, err := networkLoader.Load( ctx, - logger.WithNamespace("network"), + networkLogger(logger, creationParams), creationParams, &network.Opts{ Config: networkConfig, @@ -119,20 +116,19 @@ func (d *Daemon) CreateNetwork( var ( creationParams = bootstrap.NewCreationParams(name, domain) networkConfig = pickNetworkConfig(d.daemonConfig, creationParams) + networkLogger = networkLogger(d.logger, creationParams) ) - ctx = mctx.WithAnnotator(ctx, creationParams) - if joined, err := alreadyJoined(ctx, d.networks, creationParams); err != nil { return fmt.Errorf("checking if already joined to network: %w", err) } else if joined { return ErrAlreadyJoined } - d.logger.Info(ctx, "Creating network") + networkLogger.Info(ctx, "Creating network") n, err := d.networkLoader.Create( ctx, - d.logger.WithNamespace("network"), + networkLogger, creationParams, ipNet, hostName, @@ -144,7 +140,7 @@ func (d *Daemon) CreateNetwork( return fmt.Errorf("creating network: %w", err) } - d.logger.Info(ctx, "Network created successfully") + networkLogger.Info(ctx, "Network created successfully") d.networks[creationParams.ID] = joinedNetwork{n, networkConfig} return nil } @@ -164,20 +160,21 @@ func (d *Daemon) JoinNetwork( creationParams = newBootstrap.Bootstrap.NetworkCreationParams networkID = creationParams.ID networkConfig = pickNetworkConfig(d.daemonConfig, creationParams) + networkLogger = networkLogger( + d.logger, newBootstrap.Bootstrap.NetworkCreationParams, + ) ) - ctx = mctx.WithAnnotator(ctx, newBootstrap.Bootstrap.NetworkCreationParams) - if joined, err := alreadyJoined(ctx, d.networks, creationParams); err != nil { return fmt.Errorf("checking if already joined to network: %w", err) } else if joined { return ErrAlreadyJoined } - d.logger.Info(ctx, "Joining network") + networkLogger.Info(ctx, "Joining network") n, err := d.networkLoader.Join( ctx, - d.logger.WithNamespace("network"), + networkLogger, newBootstrap, &network.Opts{ Config: networkConfig, @@ -189,7 +186,7 @@ func (d *Daemon) JoinNetwork( ) } - d.logger.Info(ctx, "Network joined successfully") + networkLogger.Info(ctx, "Network joined successfully") d.networks[networkID] = joinedNetwork{n, networkConfig} return nil } diff --git a/go/daemon/network.go b/go/daemon/network.go index d0d7628..815031d 100644 --- a/go/daemon/network.go +++ b/go/daemon/network.go @@ -5,8 +5,16 @@ import ( "fmt" "isle/bootstrap" "isle/daemon/network" + + "dev.mediocregopher.com/mediocre-go-lib.git/mlog" ) +func networkLogger( + logger *mlog.Logger, creationParams bootstrap.CreationParams, +) *mlog.Logger { + return logger.WithNamespace("networks").WithNamespace(creationParams.Domain) +} + func pickNetwork( ctx context.Context, networkLoader network.Loader, diff --git a/go/daemon/network/loader.go b/go/daemon/network/loader.go index 9de4237..2fb5e0b 100644 --- a/go/daemon/network/loader.go +++ b/go/daemon/network/loader.go @@ -223,7 +223,7 @@ func (l *loader) Load( return load( ctx, - logger.WithNamespace("network"), + logger, l.envBinDirPath, l.nebulaDeviceNamer, networkStateDir, @@ -256,7 +256,7 @@ func (l *loader) Join( return join( ctx, - logger.WithNamespace("network"), + logger, l.envBinDirPath, l.nebulaDeviceNamer, joiningBootstrap, @@ -289,7 +289,7 @@ func (l *loader) Create( return create( ctx, - logger.WithNamespace("network"), + logger, l.envBinDirPath, l.nebulaDeviceNamer, networkStateDir, diff --git a/tasks/v0.0.3/code/dnsmasq-logging-fix.md b/tasks/v0.0.3/code/dnsmasq-logging-fix.md new file mode 100644 index 0000000..9e1ce1d --- /dev/null +++ b/tasks/v0.0.3/code/dnsmasq-logging-fix.md @@ -0,0 +1,8 @@ +--- +type: task +--- + +# Fix dnsmasq Logging Capture + +The dnsmasq process's logging is not being captured into mlog, but instead is +being written directly to stdout/stderr.