logger

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelDebug = slog.LevelDebug
	LevelInfo  = slog.LevelInfo
	LevelWarn  = slog.LevelWarn
	LevelError = slog.LevelError
)

Logger levels

View Source
const (
	RequestIDKey contextKey = "request_id"
	VendorKey    contextKey = "vendor"
	ModelKey     contextKey = "model"
)

Variables

View Source
var DefaultConfig = Config{
	Level:      LevelInfo,
	Format:     "json",
	Output:     "stdout",
	TimeFormat: time.RFC3339,
}

Default configuration

View Source
var Logger *slog.Logger

Global logger instance

Functions

func Debug

func Debug(msg string, args ...any)

Convenience functions for different log levels

func DebugCtx

func DebugCtx(ctx context.Context, msg string, args ...any)

Context-aware convenience functions

func Error

func Error(msg string, args ...any)

func ErrorCtx

func ErrorCtx(ctx context.Context, msg string, args ...any)

func Info

func Info(msg string, args ...any)

func InfoCtx

func InfoCtx(ctx context.Context, msg string, args ...any)

func Init

func Init(config Config) error

Initialize the global logger

func InitFromEnv

func InitFromEnv() error

Initialize with environment-based configuration

func LogCompressionInfo

func LogCompressionInfo(ctx context.Context, vendor string, originalSize, compressedSize int, compressionRatio float64)

LogCompressionInfo logs compression-related information

func LogError

func LogError(ctx context.Context, component string, err error, details map[string]any)

LogError logs errors with appropriate context

func LogMetrics

func LogMetrics(ctx context.Context, operation string, duration time.Duration, success bool, details map[string]any)

LogMetrics logs performance metrics

func LogProxyRequest

func LogProxyRequest(ctx context.Context, originalModel, selectedVendor, selectedModel string, totalCombinations int)

LogProxyRequest logs the initial proxy request with vendor selection

func LogStreamingInfo

func LogStreamingInfo(ctx context.Context, vendor, model string, chunkCount int)

LogStreamingInfo logs streaming-related information

func LogValidationResult

func LogValidationResult(ctx context.Context, vendor string, success bool, validationError error)

LogValidationResult logs response validation results

func LogVendorResponse

func LogVendorResponse(ctx context.Context, vendor, actualModel, presentedModel string, responseSize int, processingTime time.Duration)

LogVendorResponse logs vendor response processing

func SanitizeMap

func SanitizeMap(data map[string]any) map[string]any

Sanitize a map of data for logging

func Warn

func Warn(msg string, args ...any)

func WarnCtx

func WarnCtx(ctx context.Context, msg string, args ...any)

func WithContext

func WithContext(ctx context.Context) *slog.Logger

Context-aware logging functions

Types

type Config

type Config struct {
	Level      slog.Level
	Format     string // "json" or "text"
	Output     string // "stdout", "stderr", or file path
	TimeFormat string
}

Configuration for logger

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL