MM-30986 Move global logger init until after server logger fully configured (#16426)
- move the initGlobalLogger call to the end of initLogging so a copy of a fully configured logger is made for global logging.
Этот коммит содержится в:
@@ -597,18 +597,20 @@ func (s *Server) initLogging() error {
|
|||||||
s.Log = mlog.NewLogger(utils.MloggerConfigFromLoggerConfig(&s.Config().LogSettings, utils.GetLogFileLocation))
|
s.Log = mlog.NewLogger(utils.MloggerConfigFromLoggerConfig(&s.Config().LogSettings, utils.GetLogFileLocation))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use this app logger as the global logger (eventually remove all instances of global logging).
|
||||||
|
// This is deferred because a copy is made of the logger and it must be fully configured before
|
||||||
|
// the copy is made.
|
||||||
|
defer mlog.InitGlobalLogger(s.Log)
|
||||||
|
|
||||||
|
// Redirect default Go logger to this logger.
|
||||||
|
defer mlog.RedirectStdLog(s.Log)
|
||||||
|
|
||||||
if s.NotificationsLog == nil {
|
if s.NotificationsLog == nil {
|
||||||
notificationLogSettings := utils.GetLogSettingsFromNotificationsLogSettings(&s.Config().NotificationLogSettings)
|
notificationLogSettings := utils.GetLogSettingsFromNotificationsLogSettings(&s.Config().NotificationLogSettings)
|
||||||
s.NotificationsLog = mlog.NewLogger(utils.MloggerConfigFromLoggerConfig(notificationLogSettings, utils.GetNotificationsLogFileLocation)).
|
s.NotificationsLog = mlog.NewLogger(utils.MloggerConfigFromLoggerConfig(notificationLogSettings, utils.GetNotificationsLogFileLocation)).
|
||||||
WithCallerSkip(1).With(mlog.String("logSource", "notifications"))
|
WithCallerSkip(1).With(mlog.String("logSource", "notifications"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect default golang logger to this logger
|
|
||||||
mlog.RedirectStdLog(s.Log)
|
|
||||||
|
|
||||||
// Use this app logger as the global logger (eventually remove all instances of global logging)
|
|
||||||
mlog.InitGlobalLogger(s.Log)
|
|
||||||
|
|
||||||
if s.logListenerId != "" {
|
if s.logListenerId != "" {
|
||||||
s.RemoveConfigListener(s.logListenerId)
|
s.RemoveConfigListener(s.logListenerId)
|
||||||
}
|
}
|
||||||
@@ -638,7 +640,7 @@ func (s *Server) initLogging() error {
|
|||||||
return fmt.Errorf("invalid advanced logging config, %w", err)
|
return fmt.Errorf("invalid advanced logging config, %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := mlog.ConfigAdvancedLogging(cfg.Get()); err != nil {
|
if err := s.Log.ConfigAdvancedLogging(cfg.Get()); err != nil {
|
||||||
return fmt.Errorf("error configuring advanced logging, %w", err)
|
return fmt.Errorf("error configuring advanced logging, %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -647,7 +649,7 @@ func (s *Server) initLogging() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
listenerId := cfg.AddListener(func(_, newCfg mlog.LogTargetCfg) {
|
listenerId := cfg.AddListener(func(_, newCfg mlog.LogTargetCfg) {
|
||||||
if err := mlog.ConfigAdvancedLogging(newCfg); err != nil {
|
if err := s.Log.ConfigAdvancedLogging(newCfg); err != nil {
|
||||||
mlog.Error("Error re-configuring advanced logging", mlog.Err(err))
|
mlog.Error("Error re-configuring advanced logging", mlog.Err(err))
|
||||||
} else {
|
} else {
|
||||||
mlog.Info("Re-configured advanced logging")
|
mlog.Info("Re-configured advanced logging")
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user