cmd/cli: avoid accessing mainLog when possible

By adding a logger field to "prog" struct, and use this field inside its
method instead of always accessing global mainLog variable. This at
least ensure more consistent usage of the logger during ctrld prog
runtime, and also help refactoring the code more easily in the future
(like replacing the logger library).
This commit is contained in:
Cuong Manh Le
2025-06-17 19:20:37 +07:00
committed by Cuong Manh Le
parent 0e66697247
commit aaf31b6471
16 changed files with 323 additions and 278 deletions
+3 -3
View File
@@ -14,7 +14,7 @@ func (p *prog) watchLinkState(ctx context.Context) {
done := make(chan struct{})
defer close(done)
if err := netlink.LinkSubscribe(ch, done); err != nil {
mainLog.Load().Warn().Err(err).Msg("could not subscribe link")
p.Warn().Err(err).Msg("could not subscribe link")
return
}
for {
@@ -26,9 +26,9 @@ func (p *prog) watchLinkState(ctx context.Context) {
continue
}
if lu.Change&unix.IFF_UP != 0 {
mainLog.Load().Debug().Msgf("link state changed, re-bootstrapping")
p.Debug().Msgf("link state changed, re-bootstrapping")
for _, uc := range p.cfg.Upstream {
uc.ReBootstrap(ctrld.LoggerCtx(ctx, mainLog.Load()))
uc.ReBootstrap(ctrld.LoggerCtx(ctx, p.logger.Load()))
}
}
}