Open platform to collect and prioritize feedback
enhancement: add UserAgent to error logs (#459)
Guilherme Oenningb7c3ab2f4c56
diff --git a/app/middlewares/setup.go b/app/middlewares/setup.goindex 0ab7990da..e403ef393 100644--- a/app/middlewares/setup.go+++ b/app/middlewares/setup.go@@ -111,17 +111,17 @@ func WebSetup() web.MiddlewareFunc {return func(next web.HandlerFunc) web.HandlerFunc {return func(c web.Context) error {start := time.Now()- c.Logger().Debugf("@{HttpMethod:magenta} @{RequestURI:magenta} started", log.Props{+ c.Logger().Debugf("@{HttpMethod:magenta} @{URL:magenta} started", log.Props{"HttpMethod": c.Request.Method,- "RequestURI": c.Request.URL.RequestURI(),+ "URL": c.Request.URL.String(),})trx, err := c.Engine().Database().Begin()if err != nil {err = c.Failure(err)- c.Logger().Debugf("@{HttpMethod:magenta} @{RequestURI:magenta} finished in @{ElapsedMs:magenta}ms", log.Props{+ c.Logger().Debugf("@{HttpMethod:magenta} @{URL:magenta} finished in @{ElapsedMs:magenta}ms", log.Props{"HttpMethod": c.Request.Method,- "RequestURI": c.Request.URL.RequestURI(),+ "URL": c.Request.URL.String(),"ElapsedMs": time.Since(start).Nanoseconds() / int64(time.Millisecond),})return err@@ -151,9 +151,9 @@ func WebSetup() web.MiddlewareFunc {}c.Failure(err)c.Rollback()- c.Logger().Debugf("@{HttpMethod:magenta} @{RequestURI:magenta} panicked in @{ElapsedMs:magenta}ms (rolled back)", log.Props{+ c.Logger().Debugf("@{HttpMethod:magenta} @{URL:magenta} panicked in @{ElapsedMs:magenta}ms (rolled back)", log.Props{"HttpMethod": c.Request.Method,- "RequestURI": c.Request.URL.RequestURI(),+ "URL": c.Request.URL.String(),"ElapsedMs": time.Since(start).Nanoseconds() / int64(time.Millisecond),})}@@ -162,9 +162,9 @@ func WebSetup() web.MiddlewareFunc {//Execute the chainif err := next(c); err != nil {c.Rollback()- c.Logger().Debugf("@{HttpMethod:magenta} @{RequestURI:magenta} finished in @{ElapsedMs:magenta}ms (rolled back)", log.Props{+ c.Logger().Debugf("@{HttpMethod:magenta} @{URL:magenta} finished in @{ElapsedMs:magenta}ms (rolled back)", log.Props{"HttpMethod": c.Request.Method,- "RequestURI": c.Request.URL.RequestURI(),+ "URL": c.Request.URL.String(),"ElapsedMs": time.Since(start).Nanoseconds() / int64(time.Millisecond),})return err@@ -175,18 +175,18 @@ func WebSetup() web.MiddlewareFunc {c.Logger().Errorf("Failed to commit request with: @{Error}", log.Props{"Error": err.Error(),})- c.Logger().Debugf("@{HttpMethod:magenta} @{RequestURI:magenta} finished in @{ElapsedMs:magenta}ms (rolled back)", log.Props{+ c.Logger().Debugf("@{HttpMethod:magenta} @{URL:magenta} finished in @{ElapsedMs:magenta}ms (rolled back)", log.Props{"HttpMethod": c.Request.Method,- "RequestURI": c.Request.URL.RequestURI(),+ "URL": c.Request.URL.String(),"ElapsedMs": time.Since(start).Nanoseconds() / int64(time.Millisecond),})return err}//Still no errors, everything is fine!- c.Logger().Debugf("@{HttpMethod:magenta} @{RequestURI:magenta} finished in @{ElapsedMs:magenta}ms (committed)", log.Props{+ c.Logger().Debugf("@{HttpMethod:magenta} @{URL:magenta} finished in @{ElapsedMs:magenta}ms (committed)", log.Props{"HttpMethod": c.Request.Method,- "RequestURI": c.Request.URL.RequestURI(),+ "URL": c.Request.URL.String(),"ElapsedMs": time.Since(start).Nanoseconds() / int64(time.Millisecond),})return nildiff --git a/app/pkg/web/context.go b/app/pkg/web/context.goindex 641d204e4..c5a4f5822 100644--- a/app/pkg/web/context.go+++ b/app/pkg/web/context.go@@ -215,7 +215,10 @@ func (ctx *Context) Failure(err error) error {}ctx.Logger().Errorf(err.Error(), log.Props{- "Body": ctx.Request.Body,+ "Body": ctx.Request.Body,+ "HttpMethod": ctx.Request.Method,+ "URL": ctx.Request.URL.String(),+ "UserAgent": ctx.Request.GetHeader("User-Agent"),})ctx.Render(http.StatusInternalServerError, "500.html", Props{