From 9cdbca7dc1dfea922fc4c3f63845d7283e7de32c Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Sun, 6 Aug 2023 17:23:59 +0000 Subject: [PATCH] definite restart --- snippetbox/cmd/web/main.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/snippetbox/cmd/web/main.go b/snippetbox/cmd/web/main.go index a7d9d57..6455f18 100644 --- a/snippetbox/cmd/web/main.go +++ b/snippetbox/cmd/web/main.go @@ -11,13 +11,19 @@ func main() { addr := flag.String("addr", ":4000", "HTTP network address") flag.Parse() infoLog := log.New(os.Stdout, "INFO\t", log.Ldate|log.Ltime) + errorLog := log.New(os.Stderr, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile) mux := http.NewServeMux() fileServer := http.FileServer(http.Dir("./ui/static/")) mux.Handle("/static/", http.StripPrefix("/static", fileServer)) mux.HandleFunc("/", home) mux.HandleFunc("/snippet/view", snippetView) mux.HandleFunc("/snippet/create", snippetCreate) - log.Printf("Starting server on %s", *addr) - err := http.ListenAndServe(*addr, mux) - log.Fatal(err) + srv := &http.Server{ + Addr: *addr, + ErrorLog: errorLog, + Handler: mux, + } + infoLog.Printf("Starting server on %s", *addr) + err := srv.ListenAndServe() + errorLog.Fatal(err) }