🔧 config: add log output file configuration and cleanup example files

This commit is contained in:
2026-04-04 13:54:59 +02:00
parent c41611281b
commit 25d8940db4
7 changed files with 98 additions and 74 deletions

View File

@@ -2,6 +2,7 @@ package main
import (
"context"
"os"
"DanceLessonsCoach/pkg/config"
"DanceLessonsCoach/pkg/server"
@@ -15,6 +16,9 @@ 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()
@@ -25,3 +29,23 @@ 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")
}