mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-18 20:30:51 +08:00
refactor(logging): dedupe auth selection debug logs
Extract repeated debug logging for selected auth credentials into a helper so execute, count, and stream paths stay consistent.
This commit is contained in:
@@ -386,25 +386,7 @@ func (m *Manager) executeWithProvider(ctx context.Context, provider string, req
|
|||||||
return cliproxyexecutor.Response{}, errPick
|
return cliproxyexecutor.Response{}, errPick
|
||||||
}
|
}
|
||||||
|
|
||||||
entry := logEntryWithRequestID(ctx)
|
debugLogAuthSelection(ctx, auth, provider, req.Model)
|
||||||
if log.IsLevelEnabled(log.DebugLevel) {
|
|
||||||
accountType, accountInfo := auth.AccountInfo()
|
|
||||||
proxyInfo := auth.ProxyInfo()
|
|
||||||
if accountType == "api_key" {
|
|
||||||
if proxyInfo != "" {
|
|
||||||
entry.Debugf("Use API key %s for model %s %s", util.HideAPIKey(accountInfo), req.Model, proxyInfo)
|
|
||||||
} else {
|
|
||||||
entry.Debugf("Use API key %s for model %s", util.HideAPIKey(accountInfo), req.Model)
|
|
||||||
}
|
|
||||||
} else if accountType == "oauth" {
|
|
||||||
ident := formatOauthIdentity(auth, provider, accountInfo)
|
|
||||||
if proxyInfo != "" {
|
|
||||||
entry.Debugf("Use OAuth %s for model %s %s", ident, req.Model, proxyInfo)
|
|
||||||
} else {
|
|
||||||
entry.Debugf("Use OAuth %s for model %s", ident, req.Model)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tried[auth.ID] = struct{}{}
|
tried[auth.ID] = struct{}{}
|
||||||
execCtx := ctx
|
execCtx := ctx
|
||||||
@@ -450,25 +432,7 @@ func (m *Manager) executeCountWithProvider(ctx context.Context, provider string,
|
|||||||
return cliproxyexecutor.Response{}, errPick
|
return cliproxyexecutor.Response{}, errPick
|
||||||
}
|
}
|
||||||
|
|
||||||
entry := logEntryWithRequestID(ctx)
|
debugLogAuthSelection(ctx, auth, provider, req.Model)
|
||||||
if log.IsLevelEnabled(log.DebugLevel) {
|
|
||||||
accountType, accountInfo := auth.AccountInfo()
|
|
||||||
proxyInfo := auth.ProxyInfo()
|
|
||||||
if accountType == "api_key" {
|
|
||||||
if proxyInfo != "" {
|
|
||||||
entry.Debugf("Use API key %s for model %s %s", util.HideAPIKey(accountInfo), req.Model, proxyInfo)
|
|
||||||
} else {
|
|
||||||
entry.Debugf("Use API key %s for model %s", util.HideAPIKey(accountInfo), req.Model)
|
|
||||||
}
|
|
||||||
} else if accountType == "oauth" {
|
|
||||||
ident := formatOauthIdentity(auth, provider, accountInfo)
|
|
||||||
if proxyInfo != "" {
|
|
||||||
entry.Debugf("Use OAuth %s for model %s %s", ident, req.Model, proxyInfo)
|
|
||||||
} else {
|
|
||||||
entry.Debugf("Use OAuth %s for model %s", ident, req.Model)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tried[auth.ID] = struct{}{}
|
tried[auth.ID] = struct{}{}
|
||||||
execCtx := ctx
|
execCtx := ctx
|
||||||
@@ -514,25 +478,7 @@ func (m *Manager) executeStreamWithProvider(ctx context.Context, provider string
|
|||||||
return nil, errPick
|
return nil, errPick
|
||||||
}
|
}
|
||||||
|
|
||||||
entry := logEntryWithRequestID(ctx)
|
debugLogAuthSelection(ctx, auth, provider, req.Model)
|
||||||
if log.IsLevelEnabled(log.DebugLevel) {
|
|
||||||
accountType, accountInfo := auth.AccountInfo()
|
|
||||||
proxyInfo := auth.ProxyInfo()
|
|
||||||
if accountType == "api_key" {
|
|
||||||
if proxyInfo != "" {
|
|
||||||
entry.Debugf("Use API key %s for model %s %s", util.HideAPIKey(accountInfo), req.Model, proxyInfo)
|
|
||||||
} else {
|
|
||||||
entry.Debugf("Use API key %s for model %s", util.HideAPIKey(accountInfo), req.Model)
|
|
||||||
}
|
|
||||||
} else if accountType == "oauth" {
|
|
||||||
ident := formatOauthIdentity(auth, provider, accountInfo)
|
|
||||||
if proxyInfo != "" {
|
|
||||||
entry.Debugf("Use OAuth %s for model %s %s", ident, req.Model, proxyInfo)
|
|
||||||
} else {
|
|
||||||
entry.Debugf("Use OAuth %s for model %s", ident, req.Model)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tried[auth.ID] = struct{}{}
|
tried[auth.ID] = struct{}{}
|
||||||
execCtx := ctx
|
execCtx := ctx
|
||||||
@@ -1620,6 +1566,35 @@ func logEntryWithRequestID(ctx context.Context) *log.Entry {
|
|||||||
return log.NewEntry(log.StandardLogger())
|
return log.NewEntry(log.StandardLogger())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func debugLogAuthSelection(ctx context.Context, auth *Auth, provider string, model string) {
|
||||||
|
if !log.IsLevelEnabled(log.DebugLevel) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if auth == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
entry := logEntryWithRequestID(ctx)
|
||||||
|
accountType, accountInfo := auth.AccountInfo()
|
||||||
|
proxyInfo := auth.ProxyInfo()
|
||||||
|
if accountType == "api_key" {
|
||||||
|
if proxyInfo != "" {
|
||||||
|
entry.Debugf("Use API key %s for model %s %s", util.HideAPIKey(accountInfo), model, proxyInfo)
|
||||||
|
} else {
|
||||||
|
entry.Debugf("Use API key %s for model %s", util.HideAPIKey(accountInfo), model)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if accountType != "oauth" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ident := formatOauthIdentity(auth, provider, accountInfo)
|
||||||
|
if proxyInfo != "" {
|
||||||
|
entry.Debugf("Use OAuth %s for model %s %s", ident, model, proxyInfo)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
entry.Debugf("Use OAuth %s for model %s", ident, model)
|
||||||
|
}
|
||||||
|
|
||||||
func formatOauthIdentity(auth *Auth, provider string, accountInfo string) string {
|
func formatOauthIdentity(auth *Auth, provider string, accountInfo string) string {
|
||||||
if auth == nil {
|
if auth == nil {
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
Reference in New Issue
Block a user