Can anyone help me how to write log files in gin middleware?
func Logger() gin.HandlerFunc {
return func(c *gin.Context) {
// before
// how to convert context object to string?
c.Next()
// before
// how to convert context object to string?
}
}
You can’t “convert” a gin.Context to a string as it is a struct that wraps (amongst other things), the request, response and URL parameters. Logging all of those would not be sensible.
You should call log.Printf(...) on the specific fields you want to log.