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.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user