mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 12:20:52 +08:00
refactor(logging): streamline auth selection debug messages
Reduce duplicate Debugf calls by appending proxy info via an optional suffix and keep the debug-level guard inside the helper.
This commit is contained in:
@@ -386,10 +386,8 @@ func (m *Manager) executeWithProvider(ctx context.Context, provider string, req
|
|||||||
return cliproxyexecutor.Response{}, errPick
|
return cliproxyexecutor.Response{}, errPick
|
||||||
}
|
}
|
||||||
|
|
||||||
if log.IsLevelEnabled(log.DebugLevel) {
|
entry := logEntryWithRequestID(ctx)
|
||||||
entry := logEntryWithRequestID(ctx)
|
debugLogAuthSelection(entry, auth, provider, req.Model)
|
||||||
debugLogAuthSelection(entry, auth, provider, req.Model)
|
|
||||||
}
|
|
||||||
|
|
||||||
tried[auth.ID] = struct{}{}
|
tried[auth.ID] = struct{}{}
|
||||||
execCtx := ctx
|
execCtx := ctx
|
||||||
@@ -435,10 +433,8 @@ func (m *Manager) executeCountWithProvider(ctx context.Context, provider string,
|
|||||||
return cliproxyexecutor.Response{}, errPick
|
return cliproxyexecutor.Response{}, errPick
|
||||||
}
|
}
|
||||||
|
|
||||||
if log.IsLevelEnabled(log.DebugLevel) {
|
entry := logEntryWithRequestID(ctx)
|
||||||
entry := logEntryWithRequestID(ctx)
|
debugLogAuthSelection(entry, auth, provider, req.Model)
|
||||||
debugLogAuthSelection(entry, auth, provider, req.Model)
|
|
||||||
}
|
|
||||||
|
|
||||||
tried[auth.ID] = struct{}{}
|
tried[auth.ID] = struct{}{}
|
||||||
execCtx := ctx
|
execCtx := ctx
|
||||||
@@ -484,10 +480,8 @@ func (m *Manager) executeStreamWithProvider(ctx context.Context, provider string
|
|||||||
return nil, errPick
|
return nil, errPick
|
||||||
}
|
}
|
||||||
|
|
||||||
if log.IsLevelEnabled(log.DebugLevel) {
|
entry := logEntryWithRequestID(ctx)
|
||||||
entry := logEntryWithRequestID(ctx)
|
debugLogAuthSelection(entry, auth, provider, req.Model)
|
||||||
debugLogAuthSelection(entry, auth, provider, req.Model)
|
|
||||||
}
|
|
||||||
|
|
||||||
tried[auth.ID] = struct{}{}
|
tried[auth.ID] = struct{}{}
|
||||||
execCtx := ctx
|
execCtx := ctx
|
||||||
@@ -1576,25 +1570,24 @@ func logEntryWithRequestID(ctx context.Context) *log.Entry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func debugLogAuthSelection(entry *log.Entry, auth *Auth, provider string, model string) {
|
func debugLogAuthSelection(entry *log.Entry, auth *Auth, provider string, model string) {
|
||||||
|
if !log.IsLevelEnabled(log.DebugLevel) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if entry == nil || auth == nil {
|
if entry == nil || auth == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
accountType, accountInfo := auth.AccountInfo()
|
accountType, accountInfo := auth.AccountInfo()
|
||||||
proxyInfo := auth.ProxyInfo()
|
proxyInfo := auth.ProxyInfo()
|
||||||
|
suffix := ""
|
||||||
|
if proxyInfo != "" {
|
||||||
|
suffix = " " + proxyInfo
|
||||||
|
}
|
||||||
switch accountType {
|
switch accountType {
|
||||||
case "api_key":
|
case "api_key":
|
||||||
if proxyInfo != "" {
|
entry.Debugf("Use API key %s for model %s%s", util.HideAPIKey(accountInfo), model, suffix)
|
||||||
entry.Debugf("Use API key %s for model %s %s", util.HideAPIKey(accountInfo), model, proxyInfo)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
entry.Debugf("Use API key %s for model %s", util.HideAPIKey(accountInfo), model)
|
|
||||||
case "oauth":
|
case "oauth":
|
||||||
ident := formatOauthIdentity(auth, provider, accountInfo)
|
ident := formatOauthIdentity(auth, provider, accountInfo)
|
||||||
if proxyInfo != "" {
|
entry.Debugf("Use OAuth %s for model %s%s", ident, model, suffix)
|
||||||
entry.Debugf("Use OAuth %s for model %s %s", ident, model, proxyInfo)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
entry.Debugf("Use OAuth %s for model %s", ident, model)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user