From b1ad6e98445cf7dafa6fec1e2e769051fe7cb748 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sat, 8 Jun 2024 00:21:51 +0200 Subject: feat: Add encoding and size to log --- pkg/ext/log.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/ext/log.go b/pkg/ext/log.go index a9d26a9..2439f19 100644 --- a/pkg/ext/log.go +++ b/pkg/ext/log.go @@ -8,6 +8,7 @@ import ( type statusWraper struct { statusCode int + size int innerWriter http.ResponseWriter } @@ -16,6 +17,7 @@ func (s *statusWraper) Header() http.Header { } func (s *statusWraper) Write(b []byte) (int, error) { + s.size += len(b) return s.innerWriter.Write(b) } @@ -42,12 +44,15 @@ func Log(next http.HandlerFunc) http.HandlerFunc { t := time.Now() s := wrap(w) next(s, r) + encoding := s.Header().Get("Content-Encoding") slog.Info( - "Http request", + "HTTP request", "method", r.Method, "code", s.StatusCode(), "path", r.URL, + "encoding", encoding, "elapsed", time.Since(t), + "body-size", s.size, ) } } -- cgit v1.2.3