From 334904fc039b5c8cbc16b463e116291348667852 Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Thu, 29 Feb 2024 16:12:08 +0100 Subject: [PATCH] Actually log request to stdout to be captured by systemd --- pkg/http/logger.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/http/logger.go b/pkg/http/logger.go index 91d7f54..c3557f8 100644 --- a/pkg/http/logger.go +++ b/pkg/http/logger.go @@ -8,6 +8,7 @@ package http import ( "log" "net/http" + "os" "time" ) @@ -34,6 +35,7 @@ func (w *loggerResponseWriter) Flush() { } func LogRequest(next http.Handler) http.Handler { + stdout := log.New(os.Stdout, "", log.LstdFlags) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { t := time.Now() logger := loggerResponseWriter{w, 0, 0} @@ -45,7 +47,7 @@ func LogRequest(next http.Handler) http.Handler { if statusCode == 0 { statusCode = http.StatusOK } - log.Printf("HTTP - %s %s \"%s\" %d %d %s\n", + stdout.Printf("HTTP - %s %s \"%s\" %d %d %s\n", RemoteAddr(r), r.Method, requestPath,