diff options
Diffstat (limited to 'modules/context/access_log.go')
-rw-r--r-- | modules/context/access_log.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/modules/context/access_log.go b/modules/context/access_log.go index 515682b64b..64d204733b 100644 --- a/modules/context/access_log.go +++ b/modules/context/access_log.go @@ -7,6 +7,7 @@ import ( "bytes" "context" "fmt" + "net" "net/http" "strings" "text/template" @@ -67,17 +68,23 @@ func AccessLogger() func(http.Handler) http.Handler { requestID = parseRequestIDFromRequestHeader(req) } + reqHost, _, err := net.SplitHostPort(req.RemoteAddr) + if err != nil { + reqHost = req.RemoteAddr + } + next.ServeHTTP(w, r) rw := w.(ResponseWriter) buf := bytes.NewBuffer([]byte{}) - err := logTemplate.Execute(buf, routerLoggerOptions{ + err = logTemplate.Execute(buf, routerLoggerOptions{ req: req, Identity: &identity, Start: &start, ResponseWriter: rw, Ctx: map[string]interface{}{ "RemoteAddr": req.RemoteAddr, + "RemoteHost": reqHost, "Req": req, }, RequestID: &requestID, |