Log requests to stdout

This is so that i can have two output files: the one with accesses
(stdout) and the one with errors (stderr).
This commit is contained in:
jordi fita mas 2023-06-13 15:08:23 +02:00
parent 3c14447ef9
commit eb207a01fc
1 changed files with 3 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package pkg
import (
"log"
"net/http"
"os"
"time"
)
@ -29,6 +30,7 @@ func (w *loggerResponseWriter) Flush() {
}
func Logger(handler 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}
@ -43,7 +45,7 @@ func Logger(handler http.Handler) http.Handler {
if referer == "" {
referer = "-"
}
log.Printf("HTTP - %s - - [%s] \"%s %s %s\" %d %d \"%s\" \"%s\" %s\n",
stdout.Printf("HTTP - %s - - [%s] \"%s %s %s\" %d %d \"%s\" \"%s\" %s\n",
remoteAddr(r),
t.Format("02/Jan/2006:15:04:05 -0700"),
r.Method,