From 4649cadcb5e3130ec0dd3a78b3f97041a2bcd8f0 Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Sun, 1 Feb 2026 11:31:44 +0800 Subject: [PATCH 1/2] refactor(api): centralize config change logging --- internal/api/server.go | 39 ---------------------------- internal/watcher/diff/config_diff.go | 6 +++++ 2 files changed, 6 insertions(+), 39 deletions(-) diff --git a/internal/api/server.go b/internal/api/server.go index fa77abca..f7392b9d 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -878,64 +878,30 @@ func (s *Server) UpdateClients(cfg *config.Config) { } else if toggler, ok := s.requestLogger.(interface{ SetEnabled(bool) }); ok { toggler.SetEnabled(cfg.RequestLog) } - if oldCfg != nil { - log.Debugf("request logging updated from %t to %t", previousRequestLog, cfg.RequestLog) - } else { - log.Debugf("request logging toggled to %t", cfg.RequestLog) - } } if oldCfg == nil || oldCfg.LoggingToFile != cfg.LoggingToFile || oldCfg.LogsMaxTotalSizeMB != cfg.LogsMaxTotalSizeMB { if err := logging.ConfigureLogOutput(cfg); err != nil { log.Errorf("failed to reconfigure log output: %v", err) - } else { - if oldCfg == nil { - log.Debug("log output configuration refreshed") - } else { - if oldCfg.LoggingToFile != cfg.LoggingToFile { - log.Debugf("logging_to_file updated from %t to %t", oldCfg.LoggingToFile, cfg.LoggingToFile) - } - if oldCfg.LogsMaxTotalSizeMB != cfg.LogsMaxTotalSizeMB { - log.Debugf("logs_max_total_size_mb updated from %d to %d", oldCfg.LogsMaxTotalSizeMB, cfg.LogsMaxTotalSizeMB) - } - } } } if oldCfg == nil || oldCfg.UsageStatisticsEnabled != cfg.UsageStatisticsEnabled { usage.SetStatisticsEnabled(cfg.UsageStatisticsEnabled) - if oldCfg != nil { - log.Debugf("usage_statistics_enabled updated from %t to %t", oldCfg.UsageStatisticsEnabled, cfg.UsageStatisticsEnabled) - } else { - log.Debugf("usage_statistics_enabled toggled to %t", cfg.UsageStatisticsEnabled) - } } if s.requestLogger != nil && (oldCfg == nil || oldCfg.ErrorLogsMaxFiles != cfg.ErrorLogsMaxFiles) { if setter, ok := s.requestLogger.(interface{ SetErrorLogsMaxFiles(int) }); ok { setter.SetErrorLogsMaxFiles(cfg.ErrorLogsMaxFiles) } - if oldCfg != nil { - log.Debugf("error_logs_max_files updated from %d to %d", oldCfg.ErrorLogsMaxFiles, cfg.ErrorLogsMaxFiles) - } } if oldCfg == nil || oldCfg.DisableCooling != cfg.DisableCooling { auth.SetQuotaCooldownDisabled(cfg.DisableCooling) - if oldCfg != nil { - log.Debugf("disable_cooling updated from %t to %t", oldCfg.DisableCooling, cfg.DisableCooling) - } else { - log.Debugf("disable_cooling toggled to %t", cfg.DisableCooling) - } } if oldCfg == nil || oldCfg.CodexInstructionsEnabled != cfg.CodexInstructionsEnabled { misc.SetCodexInstructionsEnabled(cfg.CodexInstructionsEnabled) - if oldCfg != nil { - log.Debugf("codex_instructions_enabled updated from %t to %t", oldCfg.CodexInstructionsEnabled, cfg.CodexInstructionsEnabled) - } else { - log.Debugf("codex_instructions_enabled toggled to %t", cfg.CodexInstructionsEnabled) - } } if s.handlers != nil && s.handlers.AuthManager != nil { @@ -945,11 +911,6 @@ func (s *Server) UpdateClients(cfg *config.Config) { // Update log level dynamically when debug flag changes if oldCfg == nil || oldCfg.Debug != cfg.Debug { util.SetLogLevel(cfg) - if oldCfg != nil { - log.Debugf("debug mode updated from %t to %t", oldCfg.Debug, cfg.Debug) - } else { - log.Debugf("debug mode toggled to %t", cfg.Debug) - } } prevSecretEmpty := true diff --git a/internal/watcher/diff/config_diff.go b/internal/watcher/diff/config_diff.go index 867c04b7..4be9f117 100644 --- a/internal/watcher/diff/config_diff.go +++ b/internal/watcher/diff/config_diff.go @@ -39,6 +39,12 @@ func BuildConfigChangeDetails(oldCfg, newCfg *config.Config) []string { if oldCfg.RequestLog != newCfg.RequestLog { changes = append(changes, fmt.Sprintf("request-log: %t -> %t", oldCfg.RequestLog, newCfg.RequestLog)) } + if oldCfg.LogsMaxTotalSizeMB != newCfg.LogsMaxTotalSizeMB { + changes = append(changes, fmt.Sprintf("logs-max-total-size-mb: %d -> %d", oldCfg.LogsMaxTotalSizeMB, newCfg.LogsMaxTotalSizeMB)) + } + if oldCfg.ErrorLogsMaxFiles != newCfg.ErrorLogsMaxFiles { + changes = append(changes, fmt.Sprintf("error-logs-max-files: %d -> %d", oldCfg.ErrorLogsMaxFiles, newCfg.ErrorLogsMaxFiles)) + } if oldCfg.RequestRetry != newCfg.RequestRetry { changes = append(changes, fmt.Sprintf("request-retry: %d -> %d", oldCfg.RequestRetry, newCfg.RequestRetry)) } From 6a258ff841203c305f7820b1c92b3f9b30899574 Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Sun, 1 Feb 2026 12:05:48 +0800 Subject: [PATCH 2/2] feat(config): track routing and cloak changes in config diff --- internal/watcher/diff/config_diff.go | 15 +++++++++++++++ sdk/cliproxy/service.go | 1 - 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/watcher/diff/config_diff.go b/internal/watcher/diff/config_diff.go index 4be9f117..ac9353b3 100644 --- a/internal/watcher/diff/config_diff.go +++ b/internal/watcher/diff/config_diff.go @@ -75,6 +75,10 @@ func BuildConfigChangeDetails(oldCfg, newCfg *config.Config) []string { changes = append(changes, fmt.Sprintf("quota-exceeded.switch-preview-model: %t -> %t", oldCfg.QuotaExceeded.SwitchPreviewModel, newCfg.QuotaExceeded.SwitchPreviewModel)) } + if oldCfg.Routing.Strategy != newCfg.Routing.Strategy { + changes = append(changes, fmt.Sprintf("routing.strategy: %s -> %s", oldCfg.Routing.Strategy, newCfg.Routing.Strategy)) + } + // API keys (redacted) and counts if len(oldCfg.APIKeys) != len(newCfg.APIKeys) { changes = append(changes, fmt.Sprintf("api-keys count: %d -> %d", len(oldCfg.APIKeys), len(newCfg.APIKeys))) @@ -147,6 +151,17 @@ func BuildConfigChangeDetails(oldCfg, newCfg *config.Config) []string { if oldExcluded.hash != newExcluded.hash { changes = append(changes, fmt.Sprintf("claude[%d].excluded-models: updated (%d -> %d entries)", i, oldExcluded.count, newExcluded.count)) } + if o.Cloak != nil && n.Cloak != nil { + if strings.TrimSpace(o.Cloak.Mode) != strings.TrimSpace(n.Cloak.Mode) { + changes = append(changes, fmt.Sprintf("claude[%d].cloak.mode: %s -> %s", i, o.Cloak.Mode, n.Cloak.Mode)) + } + if o.Cloak.StrictMode != n.Cloak.StrictMode { + changes = append(changes, fmt.Sprintf("claude[%d].cloak.strict-mode: %t -> %t", i, o.Cloak.StrictMode, n.Cloak.StrictMode)) + } + if len(o.Cloak.SensitiveWords) != len(n.Cloak.SensitiveWords) { + changes = append(changes, fmt.Sprintf("claude[%d].cloak.sensitive-words: %d -> %d", i, len(o.Cloak.SensitiveWords), len(n.Cloak.SensitiveWords))) + } + } } } diff --git a/sdk/cliproxy/service.go b/sdk/cliproxy/service.go index ee224db5..63eaf9eb 100644 --- a/sdk/cliproxy/service.go +++ b/sdk/cliproxy/service.go @@ -543,7 +543,6 @@ func (s *Service) Run(ctx context.Context) error { selector = &coreauth.RoundRobinSelector{} } s.coreManager.SetSelector(selector) - log.Infof("routing strategy updated to %s", nextStrategy) } s.applyRetryConfig(newCfg)