mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-20 05:10:52 +08:00
refactor(logging): pass request entry into auth selection log
Avoid re-creating the request-scoped log entry in the helper and use a switch for account type dispatch.
This commit is contained in:
@@ -386,7 +386,10 @@ func (m *Manager) executeWithProvider(ctx context.Context, provider string, req
|
|||||||
return cliproxyexecutor.Response{}, errPick
|
return cliproxyexecutor.Response{}, errPick
|
||||||
}
|
}
|
||||||
|
|
||||||
debugLogAuthSelection(ctx, auth, provider, req.Model)
|
if log.IsLevelEnabled(log.DebugLevel) {
|
||||||
|
entry := logEntryWithRequestID(ctx)
|
||||||
|
debugLogAuthSelection(entry, auth, provider, req.Model)
|
||||||
|
}
|
||||||
|
|
||||||
tried[auth.ID] = struct{}{}
|
tried[auth.ID] = struct{}{}
|
||||||
execCtx := ctx
|
execCtx := ctx
|
||||||
@@ -432,7 +435,10 @@ func (m *Manager) executeCountWithProvider(ctx context.Context, provider string,
|
|||||||
return cliproxyexecutor.Response{}, errPick
|
return cliproxyexecutor.Response{}, errPick
|
||||||
}
|
}
|
||||||
|
|
||||||
debugLogAuthSelection(ctx, auth, provider, req.Model)
|
if log.IsLevelEnabled(log.DebugLevel) {
|
||||||
|
entry := logEntryWithRequestID(ctx)
|
||||||
|
debugLogAuthSelection(entry, auth, provider, req.Model)
|
||||||
|
}
|
||||||
|
|
||||||
tried[auth.ID] = struct{}{}
|
tried[auth.ID] = struct{}{}
|
||||||
execCtx := ctx
|
execCtx := ctx
|
||||||
@@ -478,7 +484,10 @@ func (m *Manager) executeStreamWithProvider(ctx context.Context, provider string
|
|||||||
return nil, errPick
|
return nil, errPick
|
||||||
}
|
}
|
||||||
|
|
||||||
debugLogAuthSelection(ctx, auth, provider, req.Model)
|
if log.IsLevelEnabled(log.DebugLevel) {
|
||||||
|
entry := logEntryWithRequestID(ctx)
|
||||||
|
debugLogAuthSelection(entry, auth, provider, req.Model)
|
||||||
|
}
|
||||||
|
|
||||||
tried[auth.ID] = struct{}{}
|
tried[auth.ID] = struct{}{}
|
||||||
execCtx := ctx
|
execCtx := ctx
|
||||||
@@ -1566,33 +1575,27 @@ 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) {
|
func debugLogAuthSelection(entry *log.Entry, auth *Auth, provider string, model string) {
|
||||||
if !log.IsLevelEnabled(log.DebugLevel) {
|
if entry == nil || auth == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if auth == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
entry := logEntryWithRequestID(ctx)
|
|
||||||
accountType, accountInfo := auth.AccountInfo()
|
accountType, accountInfo := auth.AccountInfo()
|
||||||
proxyInfo := auth.ProxyInfo()
|
proxyInfo := auth.ProxyInfo()
|
||||||
if accountType == "api_key" {
|
switch accountType {
|
||||||
|
case "api_key":
|
||||||
if proxyInfo != "" {
|
if proxyInfo != "" {
|
||||||
entry.Debugf("Use API key %s for model %s %s", util.HideAPIKey(accountInfo), model, proxyInfo)
|
entry.Debugf("Use API key %s for model %s %s", util.HideAPIKey(accountInfo), model, proxyInfo)
|
||||||
} else {
|
return
|
||||||
|
}
|
||||||
entry.Debugf("Use API key %s for model %s", util.HideAPIKey(accountInfo), model)
|
entry.Debugf("Use API key %s for model %s", util.HideAPIKey(accountInfo), model)
|
||||||
}
|
case "oauth":
|
||||||
return
|
|
||||||
}
|
|
||||||
if accountType != "oauth" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ident := formatOauthIdentity(auth, provider, accountInfo)
|
ident := formatOauthIdentity(auth, provider, accountInfo)
|
||||||
if proxyInfo != "" {
|
if proxyInfo != "" {
|
||||||
entry.Debugf("Use OAuth %s for model %s %s", ident, model, proxyInfo)
|
entry.Debugf("Use OAuth %s for model %s %s", ident, model, proxyInfo)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
entry.Debugf("Use OAuth %s for model %s", ident, model)
|
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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user