diff options
author | Alan Pearce | 2024-07-01 22:15:06 +0200 |
---|---|---|
committer | Alan Pearce | 2024-07-01 22:15:06 +0200 |
commit | 94b21b286edff37496a2fe481963625ac01c30a1 (patch) | |
tree | bdfd7803dd4eb22da785331b8547ff9858e2b0e6 /internal/server/logging.go | |
parent | f076b5bd6cb82edd99be50f3dbdd39bb9be2c44e (diff) | |
download | searchix-94b21b286edff37496a2fe481963625ac01c30a1.tar.lz searchix-94b21b286edff37496a2fe481963625ac01c30a1.tar.zst searchix-94b21b286edff37496a2fe481963625ac01c30a1.zip |
feat: more structured logging
Diffstat (limited to 'internal/server/logging.go')
-rw-r--r-- | internal/server/logging.go | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/internal/server/logging.go b/internal/server/logging.go index 372972f..6e2f7c8 100644 --- a/internal/server/logging.go +++ b/internal/server/logging.go @@ -1,11 +1,10 @@ package server import ( - "fmt" - "io" "net/http" "github.com/pkg/errors" + "go.alanpearce.eu/x/log" ) type LoggingResponseWriter struct { @@ -42,7 +41,7 @@ func NewLoggingResponseWriter(w http.ResponseWriter) *LoggingResponseWriter { type wrappedHandlerOptions struct { defaultHostname string - logger io.Writer + logger *log.Logger } func wrapHandlerWithLogging(wrappedHandler http.Handler, opts wrappedHandlerOptions) http.Handler { @@ -54,13 +53,17 @@ 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\n", + opts.logger.Info( + "http request", + "scheme", scheme, + "method", r.Method, + "code", statusCode, + "path", r.URL.Path, + "location", lw.Header().Get("Location"), ) }) |