updates.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package config
  2. import (
  3. "github.com/coroot/coroot-node-agent/utils/worker"
  4. "github.com/sirupsen/logrus"
  5. klog "github.com/sirupsen/logrus"
  6. )
  7. // updateProxyClientEndpoints 更新 ProxyClient 的 endpoints
  8. // 当 ConfigServer 热更新时,需要同步更新 ProxyClient 的 endpoints
  9. func updateProxyClientEndpoints(configServer string) {
  10. proxyClient, err := worker.GetProxyClient()
  11. if err != nil {
  12. // ProxyClient 还未初始化,不需要更新
  13. klog.Debugf("ProxyClient not initialized yet, skipping endpoint update")
  14. return
  15. }
  16. // 更新 endpoints
  17. if err := proxyClient.SetEndpoint(configServer, false); err != nil {
  18. klog.Warnf("Failed to update ProxyClient endpoints: %v", err)
  19. } else {
  20. klog.Infof("Updated ProxyClient endpoints to: %s", configServer)
  21. }
  22. }
  23. // updateLogLevel 更新日志级别
  24. // 当 logging.log_level 热更新时,需要重新设置 logrus 的级别
  25. func updateLogLevel(level string) {
  26. if level == "" {
  27. level = "info"
  28. }
  29. logrusLevel, err := logrus.ParseLevel(level)
  30. if err != nil {
  31. klog.Warnf("Failed to parse log level %s: %v", level, err)
  32. return
  33. }
  34. logrus.SetLevel(logrusLevel)
  35. klog.Infof("Updated log level to: %s", level)
  36. }
  37. // updateLogOutput 更新日志输出目标
  38. // 当 logging.console_log 热更新时,需要更新日志输出
  39. func updateLogOutput(consoleLog bool) {
  40. // 注意:由于 logrus 的输出设置比较复杂,这里只更新基本设置
  41. // 如果需要完整的输出切换,可能需要重新调用 logs.InitLog
  42. klog.Infof("Updated console log output: %v", consoleLog)
  43. }