🔧 refactor: move log output setup to config package and change server logs to Trace level
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user