diff --git a/logging.go b/logging.go index 2badb6f..d210783 100644 --- a/logging.go +++ b/logging.go @@ -52,6 +52,10 @@ func (h loggingHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { } } + if url.User != req.URL.User { + url.User = req.URL.User + } + params := LogFormatterParams{ Request: req, URL: url, diff --git a/logging_test.go b/logging_test.go index 4a89cfd..d33847a 100644 --- a/logging_test.go +++ b/logging_test.go @@ -129,6 +129,22 @@ func TestLogPathRewrites(t *testing.T) { } } +func TestLogUser(t *testing.T) { + var buf bytes.Buffer + + handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + req.URL.User = url.User("foo") + w.WriteHeader(http.StatusOK) + }) + logger := LoggingHandler(&buf, handler) + + logger.ServeHTTP(httptest.NewRecorder(), newRequest(http.MethodGet, "/")) + + if !strings.Contains(buf.String(), "- foo [") { + t.Fatalf("Got log %#v, wanted substring %#v", buf.String(), "- foo [") + } +} + func BenchmarkWriteLog(b *testing.B) { loc, err := time.LoadLocation("Europe/Warsaw") if err != nil {