about summary refs log tree commit diff stats
path: root/internal/server/server.go
diff options
context:
space:
mode:
authorAlan Pearce2024-05-19 15:42:36 +0200
committerAlan Pearce2024-05-19 15:53:32 +0200
commit09ee2de72936ea0b0edc5d3360ce1c72803a817b (patch)
tree427a590fba06e58554586aad8995fcb6e7a559f3 /internal/server/server.go
parent4064f933a965f2fb2ce43d3c2d5bd54ccd33978c (diff)
downloadwebsite-09ee2de72936ea0b0edc5d3360ce1c72803a817b.tar.lz
website-09ee2de72936ea0b0edc5d3360ce1c72803a817b.tar.zst
website-09ee2de72936ea0b0edc5d3360ce1c72803a817b.zip
log in logfmt via zap, with nicer console output in dev
Diffstat (limited to 'internal/server/server.go')
-rw-r--r--internal/server/server.go19
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)
 	}()