From 65512cae7361393a7c9660fd16b59fcbadde9cbf Mon Sep 17 00:00:00 2001 From: "Philippe M. Chiasson" Date: Tue, 24 Nov 2015 15:06:33 -0500 Subject: [PATCH 1/3] Add client ip to http access logs Fixes #1447 --- command/agent/http.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/command/agent/http.go b/command/agent/http.go index 9828444d8f..5bb4d33d0a 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -295,7 +295,7 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque // Obfuscate any tokens from appearing in the logs formVals, err := url.ParseQuery(req.URL.RawQuery) if err != nil { - s.logger.Printf("[ERR] http: Failed to decode query: %s", err) + s.logger.Printf("[ERR] http: [%s] Failed to decode query: %s", strings.Split(req.RemoteAddr, ":")[0], err) resp.WriteHeader(500) return } @@ -322,14 +322,14 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque // Invoke the handler start := time.Now() defer func() { - s.logger.Printf("[DEBUG] http: Request %s %v (%v)", req.Method, logURL, time.Now().Sub(start)) + s.logger.Printf("[DEBUG] http: [%s] Request %s %v (%v)", strings.Split(req.RemoteAddr, ":")[0], req.Method, logURL, time.Now().Sub(start)) }() obj, err := handler(resp, req) // Check for an error HAS_ERR: if err != nil { - s.logger.Printf("[ERR] http: Request %s %v, error: %v", req.Method, logURL, err) + s.logger.Printf("[ERR] http: [%s] Request %s %v, error: %v", strings.Split(req.RemoteAddr, ":")[0], req.Method, logURL, err) code := 500 errMsg := err.Error() if strings.Contains(errMsg, "Permission denied") || strings.Contains(errMsg, "ACL not found") { From 21345a8a7f7462ee8af7bd2f2ab77e20aa29ccbb Mon Sep 17 00:00:00 2001 From: "Philippe M. Chiasson" Date: Wed, 30 Dec 2015 15:39:34 -0500 Subject: [PATCH 2/3] Move logged client IP to the end of the log message --- command/agent/http.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/command/agent/http.go b/command/agent/http.go index 0408c23615..f3b21467bc 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -296,7 +296,7 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque // Obfuscate any tokens from appearing in the logs formVals, err := url.ParseQuery(req.URL.RawQuery) if err != nil { - s.logger.Printf("[ERR] http: [%s] Failed to decode query: %s", strings.Split(req.RemoteAddr, ":")[0], err) + s.logger.Printf("[ERR] http: Failed to decode query: %s from=%s", err, strings.Split(req.RemoteAddr, ":")[0]) resp.WriteHeader(500) return } @@ -323,14 +323,14 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque // Invoke the handler start := time.Now() defer func() { - s.logger.Printf("[DEBUG] http: [%s] Request %s %v (%v)", strings.Split(req.RemoteAddr, ":")[0], req.Method, logURL, time.Now().Sub(start)) + s.logger.Printf("[DEBUG] http: Request %s %v (%v) from=%s", req.Method, logURL, time.Now().Sub(start), strings.Split(req.RemoteAddr, ":")[0]) }() obj, err := handler(resp, req) // Check for an error HAS_ERR: if err != nil { - s.logger.Printf("[ERR] http: [%s] Request %s %v, error: %v", strings.Split(req.RemoteAddr, ":")[0], req.Method, logURL, err) + s.logger.Printf("[ERR] http: Request %s %v, error: %v from=%s", req.Method, logURL, err, strings.Split(req.RemoteAddr, ":")[0]) code := 500 errMsg := err.Error() if strings.Contains(errMsg, "Permission denied") || strings.Contains(errMsg, "ACL not found") { From a2eddcab388f4475be6a0adb98aa7644fab15e21 Mon Sep 17 00:00:00 2001 From: "Philippe M. Chiasson" Date: Tue, 5 Jan 2016 11:49:40 -0500 Subject: [PATCH 3/3] remove address splitting --- command/agent/http.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/command/agent/http.go b/command/agent/http.go index f3b21467bc..9457cb2021 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -296,7 +296,7 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque // Obfuscate any tokens from appearing in the logs formVals, err := url.ParseQuery(req.URL.RawQuery) if err != nil { - s.logger.Printf("[ERR] http: Failed to decode query: %s from=%s", err, strings.Split(req.RemoteAddr, ":")[0]) + s.logger.Printf("[ERR] http: Failed to decode query: %s from=%s", err, req.RemoteAddr) resp.WriteHeader(500) return } @@ -323,14 +323,14 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque // Invoke the handler start := time.Now() defer func() { - s.logger.Printf("[DEBUG] http: Request %s %v (%v) from=%s", req.Method, logURL, time.Now().Sub(start), strings.Split(req.RemoteAddr, ":")[0]) + s.logger.Printf("[DEBUG] http: Request %s %v (%v) from=%s", req.Method, logURL, time.Now().Sub(start), req.RemoteAddr) }() obj, err := handler(resp, req) // Check for an error HAS_ERR: if err != nil { - s.logger.Printf("[ERR] http: Request %s %v, error: %v from=%s", req.Method, logURL, err, strings.Split(req.RemoteAddr, ":")[0]) + s.logger.Printf("[ERR] http: Request %s %v, error: %v from=%s", req.Method, logURL, err, req.RemoteAddr) code := 500 errMsg := err.Error() if strings.Contains(errMsg, "Permission denied") || strings.Contains(errMsg, "ACL not found") {