How to log response body in gin
问题 I need to log the response body in a middleware of gin, but I don't find how to get the response body. Can anyone help? I am using a middleware like this: func Logger() gin.HandlerFunc { return func(c *gin.Context) { c.Next() statusCode := c.Writer.Status() if statusCode >= 400 { //ok this is an request with error, let's make a record for it //log body here } } } My question is, how to get response body from Context in middleware? 回答1: You need to intercept writing of response and store it