all repos — homestead @ bc9315f1bb6ba8344c71f7ff281d67e232bce062

Code for my website

use zap for logging http requests as well

Alan Pearce
commit

bc9315f1bb6ba8344c71f7ff281d67e232bce062

parent

5d9c9686873144c01604e57b5710ab8d921dcbac

1 file changed, 9 insertions(+), 12 deletions(-)

changed files
M internal/server/logging.gointernal/server/logging.go
@@ -1,9 +1,8 @@
package server import ( - "fmt" - "io" "net/http" + "website/internal/log" ) type loggingResponseWriter struct {
@@ -25,7 +24,6 @@ }
type wrappedHandlerOptions struct { defaultHostname string - logger io.Writer } func wrapHandlerWithLogging(wrappedHandler http.Handler, opts wrappedHandlerOptions) http.Handler {
@@ -41,15 +39,14 @@ }
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"), ) }) }