Files
golang/internal/logging/logging.go
Gemini CLI 4807edd23a
All checks were successful
CI / Lint (pull_request) Successful in 5s
CI / Test (pull_request) Successful in 7s
CI / Build (pull_request) Successful in 7s
CI / Docker Build (pull_request) Successful in 21s
refactor(logging): move logging setup to internal/logging
Moves logging configuration and setup to a dedicated package. Updates Config struct to use nested LoggingConfig. Updates main.go to use the new logging package.
2026-01-15 18:57:01 +00:00

38 lines
716 B
Go

package logging
import (
"log/slog"
"os"
"strings"
)
// Config holds the logging configuration.
type Config struct {
Level string `yaml:"level"`
}
// Configure sets up the global logger based on the provided configuration.
func Configure(cfg Config) *slog.Logger {
opts := &slog.HandlerOptions{
Level: parseLogLevel(cfg.Level),
}
logger := slog.New(slog.NewJSONHandler(os.Stdout, opts))
slog.SetDefault(logger)
return logger
}
func parseLogLevel(level string) slog.Level {
switch strings.ToLower(level) {
case "debug":
return slog.LevelDebug
case "info":
return slog.LevelInfo
case "warn":
return slog.LevelWarn
case "error":
return slog.LevelError
default:
return slog.LevelInfo
}
}