diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-08 00:21:51 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2024-06-08 00:29:12 +0200 |
commit | b1ad6e98445cf7dafa6fec1e2e769051fe7cb748 (patch) | |
tree | 41b93a8f6f9c469d1dc733708127a15a6603798c | |
parent | 6079b1d963f34ada5c4b25363f2319901e283936 (diff) | |
download | cerrado-b1ad6e98445cf7dafa6fec1e2e769051fe7cb748.tar.gz cerrado-b1ad6e98445cf7dafa6fec1e2e769051fe7cb748.tar.bz2 cerrado-b1ad6e98445cf7dafa6fec1e2e769051fe7cb748.zip |
feat: Add encoding and size to log
-rw-r--r-- | pkg/ext/log.go | 7 |
1 files changed, 6 insertions, 1 deletions
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, ) } } |