diff options
Diffstat (limited to 'cmd/server/main.go')
-rw-r--r-- | cmd/server/main.go | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/cmd/server/main.go b/cmd/server/main.go index bae215a..464c438 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -2,12 +2,11 @@ package main import ( "fmt" - "log" - "log/slog" "os" "os/signal" "sync" + "website/internal/log" "website/internal/server" "github.com/ardanlabs/conf/v3" @@ -20,12 +19,6 @@ var ( ) func main() { - if os.Getenv("DEBUG") != "" { - slog.SetLogLoggerLevel(slog.LevelDebug) - } - log.SetFlags(log.LstdFlags | log.Lmsgprefix) - log.SetPrefix("server: ") - runtimeConfig := server.Config{} help, err := conf.Parse("", &runtimeConfig) if err != nil { @@ -33,23 +26,24 @@ func main() { fmt.Println(help) os.Exit(1) } - log.Panicf("parsing runtime configuration: %v", err) + panic("parsing runtime configuration" + err.Error()) } + log.Configure(runtimeConfig.Production) c := make(chan os.Signal, 2) signal.Notify(c, os.Interrupt) sv, err := server.New(&runtimeConfig) if err != nil { - log.Fatalf("error setting up server: %v", err) + log.Fatal("error setting up server", "error", err) } wg := &sync.WaitGroup{} wg.Add(1) go func() { defer wg.Done() sig := <-c - log.Printf("signal captured: %v", sig) + log.Info("signal captured", "sig", sig) <-sv.Stop() - slog.Debug("server stopped") + log.Debug("server stopped") }() sErr := make(chan error) @@ -59,13 +53,13 @@ func main() { sErr <- sv.Start() }() if !runtimeConfig.InDevServer { - log.Printf("server listening on %s", sv.Addr) + log.Info("server listening", "address", sv.Addr) } err = <-sErr if err != nil { // Error starting or closing listener: - log.Fatalf("error: %v", err) + log.Fatal("error", "error", err) } wg.Wait() } |