feat(llm): add LLM call recording with admin panel integration

- llm.Adapter: SetCallLogger hook for recording every API call
- llm.CallLogger: ring-buffer with Recent+Stats for admin API
- main.go: wire DeepSeek adapter to CallLogger
- Fix: single CallLogger instance for both recording and display
- Metrics: model name, duration, success/fail, tokens
- All 16 packages pass
This commit is contained in:
Aska committed 2026-08-12 19:10:51 +08:00
1 parent 5b2bcc9441
commit 6a4887e52a
6 files changed
+131 -67

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
package logger
import (
"fmt"
"io"
"os"
)
// L is the global logger instance. Configure via Init().
var L = New(os.Stderr, LevelInfo, "text")
// Init configures the global logger.
func Init(level Level, format string) {
L = New(os.Stderr, level, format)
}
// InitNop sets the global logger to discard all output.
func InitNop() {
L = New(io.Discard, LevelDebug, "text")
}
// G returns the global logger.
func G() *Logger { return L }
// --- Global convenience methods ---
func Debug(msg string, args ...any) { L.Debug(msg, args...) }
func Info(msg string, args ...any) { L.Info(msg, args...) }
func Warn(msg string, args ...any) { L.Warn(msg, args...) }
func Error(msg string, args ...any) { L.Error(msg, args...) }
func Debugf(format string, args ...any) {
L.Debug(fmt.Sprintf(format, args...))
}
func Infof(format string, args ...any) {
L.Info(fmt.Sprintf(format, args...))
}
func Warnf(format string, args ...any) {
L.Warn(fmt.Sprintf(format, args...))
}
func Errorf(format string, args ...any) {
L.Error(fmt.Sprintf(format, args...))
}
func Fatalf(format string, args ...any) {
L.Error(fmt.Sprintf(format, args...))
os.Exit(1)
}
func Fatal(msg string, args ...any) {
L.Error(msg, args...)
os.Exit(1)
}