Clean up logging namespaces in daemon a bit
This commit is contained in:
parent
5e8049c8d0
commit
aac7b30cf0
@ -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")
|
||||
}()
|
||||
|
||||
{
|
||||
|
@ -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,9 +160,10 @@ 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)
|
||||
@ -174,10 +171,10 @@ func (d *Daemon) JoinNetwork(
|
||||
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
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
8
tasks/v0.0.3/code/dnsmasq-logging-fix.md
Normal file
8
tasks/v0.0.3/code/dnsmasq-logging-fix.md
Normal file
@ -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.
|
Loading…
Reference in New Issue
Block a user