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 authored and Cuong Manh Le committed 2025-02-21 20:44:27 +07:00
1 parent eff5ff580b
commit 8bd3b9e474
4 files changed
+11 -12

No files matched your search

+1 -4
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())
+9
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() {
-6
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.
//
+1 -2
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()
}