Actually log request to stdout to be captured by systemd

This commit is contained in:
jordi fita mas 2024-02-29 16:12:08 +01:00
parent 9dc4c4ef8d
commit 334904fc03
1 changed files with 3 additions and 1 deletions

View File

@ -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,