about summary refs log tree commit diff stats
path: root/internal/server/logging.go
diff options
context:
space:
mode:
authorAlan Pearce2024-05-19 15:53:09 +0200
committerAlan Pearce2024-05-19 15:53:32 +0200
commitaf7b5d9478df3da1a46e14e39fafb9fe475b0c0f (patch)
treefc889d45a1b002131f590397cb2cab6600a0836d /internal/server/logging.go
parent09ee2de72936ea0b0edc5d3360ce1c72803a817b (diff)
downloadwebsite-af7b5d9478df3da1a46e14e39fafb9fe475b0c0f.tar.lz
website-af7b5d9478df3da1a46e14e39fafb9fe475b0c0f.tar.zst
website-af7b5d9478df3da1a46e14e39fafb9fe475b0c0f.zip
use zap for logging http requests as well
Diffstat (limited to 'internal/server/logging.go')
-rw-r--r--internal/server/logging.go21
1 files changed, 9 insertions, 12 deletions
diff --git a/internal/server/logging.go b/internal/server/logging.go
index 135f06e..fcdab18 100644
--- a/internal/server/logging.go
+++ b/internal/server/logging.go
@@ -1,9 +1,8 @@
 package server
 
 import (
-	"fmt"
-	"io"
 	"net/http"
+	"website/internal/log"
 )
 
 type loggingResponseWriter struct {
@@ -25,7 +24,6 @@ func NewLoggingResponseWriter(w http.ResponseWriter) *loggingResponseWriter {
 
 type wrappedHandlerOptions struct {
 	defaultHostname string
-	logger          io.Writer
 }
 
 func wrapHandlerWithLogging(wrappedHandler http.Handler, opts wrappedHandlerOptions) http.Handler {
@@ -41,15 +39,14 @@ func wrapHandlerWithLogging(wrappedHandler http.Handler, opts wrappedHandlerOpti
 		lw := NewLoggingResponseWriter(w)
 		wrappedHandler.ServeHTTP(lw, r)
 		statusCode := lw.statusCode
-		fmt.Fprintf(
-			opts.logger,
-			"%s %s %d %s %s %s\n",
-			scheme,
-			r.Method,
-			statusCode,
-			host,
-			r.URL.Path,
-			lw.Header().Get("Location"),
+		log.Info(
+			"http request",
+			"scheme", scheme,
+			"method", r.Method,
+			"status", statusCode,
+			"host", host,
+			"path", r.URL.Path,
+			"location", lw.Header().Get("Location"),
 		)
 	})
 }