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
+2 -1
View File
@@ -100,6 +100,7 @@ func (p *prog) initLogging(backup bool) {
// Initializing internal logging after global logging.
p.initInternalLogging(logWriters)
p.logger.Store(mainLog.Load())
}
// initInternalLogging performs internal logging if there's no log enabled.
@@ -108,7 +109,7 @@ func (p *prog) initInternalLogging(writers []io.Writer) {
return
}
p.initInternalLogWriterOnce.Do(func() {
mainLog.Load().Notice().Msg("internal logging enabled")
p.Notice().Msg("internal logging enabled")
p.internalLogWriter = newLogWriter()
p.internalLogSent = time.Now().Add(-logWriterSentInterval)
p.internalWarnLogWriter = newSmallLogWriter()