Add client ip to http access logs

Fixes #1447
This commit is contained in:
Philippe M. Chiasson 2015-11-24 15:06:33 -05:00
parent 3345d73b1c
commit 65512cae73
1 changed files with 3 additions and 3 deletions

View File

@ -295,7 +295,7 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
// Obfuscate any tokens from appearing in the logs // Obfuscate any tokens from appearing in the logs
formVals, err := url.ParseQuery(req.URL.RawQuery) formVals, err := url.ParseQuery(req.URL.RawQuery)
if err != nil { 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) resp.WriteHeader(500)
return return
} }
@ -322,14 +322,14 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
// Invoke the handler // Invoke the handler
start := time.Now() start := time.Now()
defer func() { 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) obj, err := handler(resp, req)
// Check for an error // Check for an error
HAS_ERR: HAS_ERR:
if err != nil { 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 code := 500
errMsg := err.Error() errMsg := err.Error()
if strings.Contains(errMsg, "Permission denied") || strings.Contains(errMsg, "ACL not found") { if strings.Contains(errMsg, "Permission denied") || strings.Contains(errMsg, "ACL not found") {