π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[server] Log request body in output for error
Neeraj Gupta7b610dbc3481
diff --git a/server/pkg/middleware/request_logger.go b/server/pkg/middleware/request_logger.goindex 0133be5f89..360ecbbc3c 100644--- a/server/pkg/middleware/request_logger.go+++ b/server/pkg/middleware/request_logger.go@@ -77,14 +77,16 @@ func Logger(urlSanitizer func(_ *gin.Context) string) gin.HandlerFunc {"req_uri": c.Request.URL.Path,"ua": userAgent,})- if shouldSkipBodyLog(reqMethod, c.Request.URL.Path) {+ skipRequestLogUnlessError := shouldSkipBodyLog(reqMethod, c.Request.URL.Path)+ if skipRequestLogUnlessError {reqContextLogger = reqContextLogger.WithField("req_body", "redacted")} else {body, err := readBody(rdr1)if err != nil {logrus.Error("Error reading body", err)+ } else {+ reqContextLogger = reqContextLogger.WithField("req_body", body)}- reqContextLogger = reqContextLogger.WithField("req_body", body)}reqContextLogger.Info("incoming")c.Request.Body = rdr2@@ -98,6 +100,14 @@ func Logger(urlSanitizer func(_ *gin.Context) string) gin.HandlerFunc {c.Request.Host, reqURI).Observe(float64(latencyTime.Milliseconds()))}+ if statusCode >= 400 && !skipRequestLogUnlessError {+ body, err := readBody(rdr1)+ if err != nil {+ logrus.Error("Error reading body", err)+ } else {+ reqContextLogger = reqContextLogger.WithField("req_body", body)+ }+ }reqContextLogger.WithFields(logrus.Fields{"latency_time": latencyTime,"h_latency": timeUtil.HumanFriendlyDuration(latencyTime),