cmd/cli: fix missing runtime log for startup

The runtime internal log should be initialized right after normal log
from configuration, prevent missing log from any actions that could be
happened between two initializations.
This commit is contained in:
Cuong Manh Le
2025-02-19 20:01:54 +07:00
committed by Cuong Manh Le
parent eff5ff580b
commit 8bd3b9e474
4 changed files with 11 additions and 12 deletions

View File

@@ -266,10 +266,7 @@ func run(appCallback *AppCallback, stopCh chan struct{}) {
// Log config do not have thing to validate, so it's safe to init log here,
// so it's able to log information in processCDFlags.
logWriters := initLogging()
// Initializing internal logging after global logging.
p.initInternalLogging(logWriters)
p.initLogging(true)
mainLog.Load().Info().Msgf("starting ctrld %s", curVersion())
mainLog.Load().Info().Msgf("os: %s", osVersion())

View File

@@ -93,6 +93,15 @@ func (lw *logWriter) Write(p []byte) (int, error) {
return lw.buf.Write(p)
}
// initLogging initializes global logging setup.
func (p *prog) initLogging(backup bool) {
zerolog.TimeFieldFormat = time.RFC3339 + ".000"
logWriters := initLoggingWithBackup(backup)
// Initializing internal logging after global logging.
p.initInternalLogging(logWriters)
}
// initInternalLogging performs internal logging if there's no log enabled.
func (p *prog) initInternalLogging(writers []io.Writer) {
if !p.needInternalLogging() {

View File

@@ -103,12 +103,6 @@ func initConsoleLogging() {
}
}
// initLogging initializes global logging setup.
func initLogging() []io.Writer {
zerolog.TimeFieldFormat = time.RFC3339 + ".000"
return initLoggingWithBackup(true)
}
// initInteractiveLogging is like initLogging, but the ProxyLogger is discarded
// to be used for all interactive commands.
//

View File

@@ -560,13 +560,12 @@ func (p *prog) run(reload bool, reloadCh chan struct{}) {
if !reload {
// Stop writing log to unix socket.
consoleWriter.Out = os.Stdout
logWriters := initLoggingWithBackup(false)
p.initLogging(false)
if p.logConn != nil {
_ = p.logConn.Close()
}
go p.apiConfigReload()
p.postRun()
p.initInternalLogging(logWriters)
}
wg.Wait()
}