diff options
author | 2023-09-24 16:32:09 -0700 | |
---|---|---|
committer | 2023-09-24 22:37:33 -0700 | |
commit | c0e954f19d707fef8ef8271636ec661634a4c4c7 (patch) | |
tree | 5aa052a048f470e233a454e5ad9071eed1fa37c0 /internal/http/server/middleware.go | |
parent | 54cb8fa0286e4a2f1a81c32b5a89722d93b30bf7 (diff) | |
download | v2-c0e954f19d707fef8ef8271636ec661634a4c4c7.tar.gz v2-c0e954f19d707fef8ef8271636ec661634a4c4c7.tar.zst v2-c0e954f19d707fef8ef8271636ec661634a4c4c7.zip |
Implement structured logging using log/slog package
Diffstat (limited to 'internal/http/server/middleware.go')
-rw-r--r-- | internal/http/server/middleware.go | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/internal/http/server/middleware.go b/internal/http/server/middleware.go index e23cdcc4..41978471 100644 --- a/internal/http/server/middleware.go +++ b/internal/http/server/middleware.go @@ -5,11 +5,12 @@ package httpd // import "miniflux.app/v2/internal/http/server" import ( "context" + "log/slog" "net/http" + "time" "miniflux.app/v2/internal/config" "miniflux.app/v2/internal/http/request" - "miniflux.app/v2/internal/logger" ) func middleware(next http.Handler) http.Handler { @@ -22,12 +23,18 @@ func middleware(next http.Handler) http.Handler { config.Opts.HTTPS = true } - protocol := "HTTP" - if config.Opts.HTTPS { - protocol = "HTTPS" - } - - logger.Debug("[%s] %s %s %s", protocol, clientIP, r.Method, r.RequestURI) + t1 := time.Now() + defer func() { + slog.Debug("Incoming request", + slog.String("client_ip", clientIP), + slog.Group("request", + slog.String("method", r.Method), + slog.String("uri", r.RequestURI), + slog.String("protocol", r.Proto), + slog.Duration("execution_time", time.Since(t1)), + ), + ) + }() if config.Opts.HTTPS && config.Opts.HasHSTS() { w.Header().Set("Strict-Transport-Security", "max-age=31536000") |