From 3ca01b60a5801196cfef88adce6e09141bc6c48f Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Fri, 26 Sep 2025 14:01:41 +0800 Subject: [PATCH] refactor(logging): Improve client loading and registration logs --- internal/misc/credentials.go | 3 ++- internal/registry/model_registry.go | 5 +++++ internal/watcher/watcher.go | 3 +-- sdk/cliproxy/service.go | 12 ------------ 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/internal/misc/credentials.go b/internal/misc/credentials.go index b6324863..5a70e0f8 100644 --- a/internal/misc/credentials.go +++ b/internal/misc/credentials.go @@ -8,6 +8,7 @@ import ( log "github.com/sirupsen/logrus" ) +// Separator used to visually group related log lines. var credentialSeparator = strings.Repeat("-", 70) // LogSavingCredentials emits a consistent log message when persisting auth material. @@ -21,5 +22,5 @@ func LogSavingCredentials(path string) { // LogCredentialSeparator adds a visual separator to group auth/key processing logs. func LogCredentialSeparator() { - log.Info(credentialSeparator) + log.Debug(credentialSeparator) } diff --git a/internal/registry/model_registry.go b/internal/registry/model_registry.go index 079e6271..2987aa5d 100644 --- a/internal/registry/model_registry.go +++ b/internal/registry/model_registry.go @@ -9,6 +9,7 @@ import ( "sync" "time" + misc "github.com/router-for-me/CLIProxyAPI/v6/internal/misc" log "github.com/sirupsen/logrus" ) @@ -148,6 +149,8 @@ func (r *ModelRegistry) RegisterClient(clientID, clientProvider string, models [ delete(r.clientProviders, clientID) } log.Debugf("Registered client %s from provider %s with %d models", clientID, clientProvider, len(models)) + // Separator at the end of the registration block (acts as boundary to next group) + misc.LogCredentialSeparator() } // UnregisterClient removes a client and decrements counts for its models @@ -207,6 +210,8 @@ func (r *ModelRegistry) unregisterClientInternal(clientID string) { delete(r.clientProviders, clientID) } log.Debugf("Unregistered client %s", clientID) + // Separator line after completing client unregistration (after the summary line) + misc.LogCredentialSeparator() } // SetModelQuotaExceeded marks a model as quota exceeded for a specific client diff --git a/internal/watcher/watcher.go b/internal/watcher/watcher.go index e6b820d7..b6a8b0ae 100644 --- a/internal/watcher/watcher.go +++ b/internal/watcher/watcher.go @@ -561,8 +561,7 @@ func (w *Watcher) reloadClients() { w.refreshAuthState() - log.Infof("full client reload complete - old: %d clients, new: %d clients (%d auth files + %d GL API keys + %d Claude API keys + %d Codex keys + %d OpenAI-compat)", - 0, + log.Infof("full client load complete - %d clients (%d auth files + %d GL API keys + %d Claude API keys + %d Codex keys + %d OpenAI-compat)", totalNewClients, authFileCount, glAPIKeyCount, diff --git a/sdk/cliproxy/service.go b/sdk/cliproxy/service.go index 4876dada..dba2cfda 100644 --- a/sdk/cliproxy/service.go +++ b/sdk/cliproxy/service.go @@ -18,7 +18,6 @@ import ( "github.com/router-for-me/CLIProxyAPI/v6/internal/registry" "github.com/router-for-me/CLIProxyAPI/v6/internal/runtime/executor" _ "github.com/router-for-me/CLIProxyAPI/v6/internal/usage" - "github.com/router-for-me/CLIProxyAPI/v6/internal/util" "github.com/router-for-me/CLIProxyAPI/v6/internal/watcher" sdkaccess "github.com/router-for-me/CLIProxyAPI/v6/sdk/access" _ "github.com/router-for-me/CLIProxyAPI/v6/sdk/access/providers/configapikey" @@ -382,17 +381,6 @@ func (s *Service) Run(ctx context.Context) error { log.Infof("core auth auto-refresh started (interval=%s)", interval) } - authFileCount := util.CountAuthFiles(s.cfg.AuthDir) - totalNewClients := authFileCount + apiKeyResult.GeminiKeyCount + apiKeyResult.ClaudeKeyCount + apiKeyResult.CodexKeyCount + apiKeyResult.OpenAICompatCount - log.Infof("full client load complete - %d clients (%d auth files + %d GL API keys + %d Claude API keys + %d Codex keys + %d OpenAI-compat)", - totalNewClients, - authFileCount, - apiKeyResult.GeminiKeyCount, - apiKeyResult.ClaudeKeyCount, - apiKeyResult.CodexKeyCount, - apiKeyResult.OpenAICompatCount, - ) - select { case <-ctx.Done(): log.Debug("service context cancelled, shutting down...")