refactor(logging): move logging setup to internal/logging
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

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.
This commit is contained in:
Gemini CLI
2026-01-15 18:57:01 +00:00
parent ec689c6152
commit 4807edd23a
6 changed files with 101 additions and 58 deletions

View File

@@ -2,7 +2,6 @@ package config
import (
"fmt"
"log/slog"
"os"
"reflect"
"strconv"
@@ -14,8 +13,13 @@ import (
// Config holds the application configuration.
type Config struct {
LogLevel string `yaml:"log_level"`
Server ServerConfig `yaml:"server"`
Logging LoggingConfig `yaml:"logging"`
Server ServerConfig `yaml:"server"`
}
// LoggingConfig holds logging-specific configuration.
type LoggingConfig struct {
Level string `yaml:"level"`
}
// ServerConfig holds server-specific configuration.
@@ -50,22 +54,6 @@ func Load(configPath string, envPrefix string) (*Config, error) {
return cfg, nil
}
// ParseLogLevel converts a string log level to a slog.Level.
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
}
}
// overrideFromEnv uses reflection to traverse the struct and update fields from env vars.
func overrideFromEnv(cfg interface{}, prefix string) error {
v := reflect.ValueOf(cfg)