Enhance build system and logging configuration

- Add scripts/build.sh to compile binaries into bin/ directory

- Move all zerolog setup logic from cmd/server/main.go to pkg/config

- Add log level configuration support (trace, debug, info, warn, error, fatal, panic)

- Simplify cmd/server/main.go from 57 to 27 lines (53% reduction)

- Update .gitignore to use bin/ directory instead of individual files

- Document build process and bin directory in AGENTS.md

- Maintain backward compatibility with all existing functionality
This commit is contained in:
2026-04-04 13:24:33 +02:00
parent 9855f521f3
commit 00e796c608
6 changed files with 119 additions and 36 deletions

View File

@@ -2,49 +2,19 @@ package main
import (
"context"
"os"
"DanceLessonsCoach/pkg/config"
"DanceLessonsCoach/pkg/server"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func main() {
// Initialize Zerolog with default console format first
zerolog.SetGlobalLevel(zerolog.TraceLevel)
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
consoleWriter := zerolog.ConsoleWriter{Out: os.Stderr}
// Check if JSON logging is requested via environment variable
// This allows JSON logging even during config loading
jsonLogging := os.Getenv("DLC_LOGGING_JSON") == "true"
if jsonLogging {
// JSON output for structured logging
log.Logger = log.Output(os.Stderr)
} else {
// Console output for initial logging
log.Logger = log.Output(consoleWriter)
}
// Load configuration
// Load configuration (this will also setup logging)
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal().Err(err).Msg("Failed to load configuration")
}
// Reconfigure logging based on loaded configuration (overrides env var)
if cfg.Logging.JSON {
// JSON output for structured logging
log.Logger = log.Output(os.Stderr)
} else {
// Keep console output
log.Logger = log.Output(consoleWriter)
}
log.Info().Bool("json_logging", cfg.Logging.JSON).Msg("Logging configured")
// Create readiness context to control readiness state
readyCtx, readyCancel := context.WithCancel(context.Background())
defer readyCancel()