diff options
Diffstat (limited to 'internal/server/server.go')
-rw-r--r-- | internal/server/server.go | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/internal/server/server.go b/internal/server/server.go index cbee989..62e32d5 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -4,8 +4,6 @@ import ( "context" "fmt" "io" - "log" - "log/slog" "mime" "net" "net/http" @@ -16,6 +14,7 @@ import ( "time" cfg "website/internal/config" + "website/internal/log" "github.com/getsentry/sentry-go" sentryhttp "github.com/getsentry/sentry-go/http" @@ -89,7 +88,7 @@ func (fn webHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { defer func() { if fail := recover(); fail != nil { w.WriteHeader(http.StatusInternalServerError) - slog.Error("runtime panic!", "error", fail) + log.Error("runtime panic!", "error", fail) } }() w.Header().Set("Server", fmt.Sprintf("website (%s)", ShortSHA)) @@ -111,7 +110,7 @@ var newMIMEs = map[string]string{ func fixupMIMETypes() { for ext, newType := range newMIMEs { if err := mime.AddExtensionType(ext, newType); err != nil { - slog.Error("could not update mime type", "ext", ext, "mime", newType) + log.Error("could not update mime type", "ext", ext, "mime", newType) } } } @@ -134,7 +133,7 @@ func New(runtimeConfig *Config) (*Server, error) { } prefix := path.Join(runtimeConfig.Root, "public") - slog.Debug("registering content files", "prefix", prefix) + log.Debug("registering content files", "prefix", prefix) err = registerContentFiles(prefix) if err != nil { return nil, errors.WithMessagef(err, "registering content files") @@ -161,7 +160,7 @@ func New(runtimeConfig *Config) (*Server, error) { top := http.NewServeMux() mux := http.NewServeMux() - slog.Debug("binding main handler to", "host", runtimeConfig.BaseURL.Hostname()+"/") + log.Debug("binding main handler to", "host", runtimeConfig.BaseURL.Hostname()+"/") mux.Handle(runtimeConfig.BaseURL.Hostname()+"/", webHandler(serveFile)) mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -205,19 +204,19 @@ func (s *Server) Start() error { } func (s *Server) Stop() chan struct{} { - slog.Debug("stop called") + log.Debug("stop called") idleConnsClosed := make(chan struct{}) go func() { - slog.Debug("shutting down server") + log.Debug("shutting down server") ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() err := s.Server.Shutdown(ctx) - slog.Debug("server shut down") + log.Debug("server shut down") if err != nil { // Error from closing listeners, or context timeout: - log.Printf("HTTP server Shutdown: %v", err) + log.Warn("HTTP server Shutdown", "error", err) } close(idleConnsClosed) }() |