mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 13:00:52 +08:00
- Added `LoggerPlugin` to log usage metrics for observability. - Introduced a new `Manager` to handle usage record queuing and plugin registration. - Integrated new usage reporter and detailed metrics parsing into executors, covering providers like OpenAI, Codex, Claude, and Gemini. - Improved token usage breakdown across streaming and non-streaming responses.
27 lines
724 B
Go
27 lines
724 B
Go
package usage
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
coreusage "github.com/router-for-me/CLIProxyAPI/v6/sdk/cliproxy/usage"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func init() {
|
|
coreusage.RegisterPlugin(NewLoggerPlugin())
|
|
}
|
|
|
|
// LoggerPlugin outputs every usage record to the application log.
|
|
type LoggerPlugin struct{}
|
|
|
|
// NewLoggerPlugin constructs a new logger plugin instance.
|
|
func NewLoggerPlugin() *LoggerPlugin { return &LoggerPlugin{} }
|
|
|
|
// HandleUsage implements coreusage.Plugin.
|
|
func (p *LoggerPlugin) HandleUsage(ctx context.Context, record coreusage.Record) {
|
|
// Output all relevant fields for observability; keep logging lightweight and non-blocking.
|
|
data, _ := json.Marshal(record)
|
|
log.Debug(string(data))
|
|
}
|