🔧 refactor: move log output setup to config package and change server logs to Trace level

This commit is contained in:
2026-04-04 14:05:06 +02:00
parent 25d8940db4
commit 3c1aaea789
3 changed files with 35 additions and 36 deletions

View File

@@ -2,7 +2,6 @@ package main
import (
"context"
"os"
"DanceLessonsCoach/pkg/config"
"DanceLessonsCoach/pkg/server"
@@ -16,9 +15,6 @@ func main() {
log.Fatal().Err(err).Msg("Failed to load configuration")
}
// Setup log output based on configuration
setupLogOutput(cfg)
// Create readiness context to control readiness state
readyCtx, readyCancel := context.WithCancel(context.Background())
defer readyCancel()
@@ -29,23 +25,3 @@ func main() {
log.Fatal().Err(err).Msg("Server failed")
}
}
// setupLogOutput configures the log output based on configuration
func setupLogOutput(cfg *config.Config) {
output := cfg.GetLogOutput()
if output == "" {
// Use stderr by default
return
}
// Open the log file
file, err := os.OpenFile(output, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.Error().Err(err).Str("output", output).Msg("Failed to open log file, using stderr")
return
}
// Set the log output
log.Logger = log.Output(file)
log.Info().Str("output", output).Msg("Logging to file")
}