Files
hobokenchicken 1f574d8134
CI / Lint (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Build (push) Has been cancelled
feat: Phase 2 - reliability & observability
- Circuit breaker: proper thresholds (3 failures, 30s timeout)
- HTTP timeouts: 30s on all providers (was no timeout)
- Structured logging: slog replaces fmt.Printf throughout
- Stream errors: propagated as SSE error events to client
- Registry fetch: retry with backoff (3 attempts)
- Registry reads in dashboard protected by RWMutex
2026-04-26 14:48:56 -04:00

48 lines
873 B
Go

package logger
import (
"context"
"log/slog"
"os"
"strings"
)
var level = slog.LevelInfo
func init() {
env := os.Getenv("LLM_PROXY_LOG_LEVEL")
switch strings.ToLower(env) {
case "debug":
level = slog.LevelDebug
case "warn":
level = slog.LevelWarn
case "error":
level = slog.LevelError
}
h := slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
Level: level,
})
slog.SetDefault(slog.New(h))
}
// Warn is a helper to emit structured warnings.
func Warn(msg string, args ...any) {
slog.Warn(msg, args...)
}
// Error is a helper to emit structured errors.
func Error(msg string, args ...any) {
slog.Error(msg, args...)
}
// Debug is a helper to emit structured debug messages.
func Debug(msg string, args ...any) {
slog.Debug(msg, args...)
}
// Ctx wraps slog with context.
func Ctx(ctx context.Context) *slog.Logger {
return slog.Default()
}