diff --git a/api/router.go b/api/router.go index 8c683f4b7bbf6f5f457c6dc65696b2c6ac296589..79430516b02c7bc0ebcbe45cc9ae1ade9dc8ba43 100644 --- a/api/router.go +++ b/api/router.go @@ -11,6 +11,7 @@ import ( "github.com/sirupsen/logrus" "github.com/turt2live/matrix-media-repo/api/_responses" "github.com/turt2live/matrix-media-repo/api/_routers" + "github.com/turt2live/matrix-media-repo/util" ) func buildPrimaryRouter() *httprouter.Router { @@ -54,7 +55,7 @@ func finishCorsFn(w http.ResponseWriter, r *http.Request) { } func panicFn(w http.ResponseWriter, r *http.Request, i interface{}) { - logrus.Errorf("Panic received on %s %s: %s", r.Method, r.URL.String(), i) + logrus.Errorf("Panic received on %s %s: %s", r.Method, util.GetLogSafeUrl(r), i) if e, ok := i.(error); ok { sentry.CaptureException(e) diff --git a/util/http.go b/util/http.go index 83aef1db3273575b9863fbab8ecc471137b1a27e..1bfd1a2b973d36d15e91d5ab110bda4b80d5a4d4 100644 --- a/util/http.go +++ b/util/http.go @@ -2,6 +2,7 @@ package util import ( "net/http" + "net/url" "strings" "github.com/sirupsen/logrus" @@ -37,3 +38,9 @@ func GetLogSafeQueryString(r *http.Request) string { return qs.Encode() } + +func GetLogSafeUrl(r *http.Request) string { + copyUrl, _ := url.ParseRequestURI(r.URL.String()) + copyUrl.RawQuery = GetLogSafeQueryString(r) + return copyUrl.String() +}