- 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
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
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)
|
|
}
|