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:
parent
3c14447ef9
commit
eb207a01fc
|
@ -3,6 +3,7 @@ package pkg
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,6 +30,7 @@ func (w *loggerResponseWriter) Flush() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Logger(handler http.Handler) http.Handler {
|
func Logger(handler http.Handler) http.Handler {
|
||||||
|
stdout := log.New(os.Stdout, "", log.LstdFlags)
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
logger := loggerResponseWriter{w, 0, 0}
|
logger := loggerResponseWriter{w, 0, 0}
|
||||||
|
@ -43,7 +45,7 @@ func Logger(handler http.Handler) http.Handler {
|
||||||
if referer == "" {
|
if referer == "" {
|
||||||
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),
|
remoteAddr(r),
|
||||||
t.Format("02/Jan/2006:15:04:05 -0700"),
|
t.Format("02/Jan/2006:15:04:05 -0700"),
|
||||||
r.Method,
|
r.Method,
|
||||||
|
|
Loading…
Reference in New Issue