Update readme for showing output log to file (#1073)

* Update readme for showing output log to file

* update indent
This commit is contained in:
田欧 2017-08-22 13:55:32 +08:00 committed by Bo-Yi Wu
parent f4c9ac17a4
commit 8be30bd382

View File

@ -381,7 +381,8 @@ func main() {
r := gin.New() r := gin.New()
// Global middleware // Global middleware
// Logger middleware will write the logs to gin.DefaultWriter even you set with GIN_MODE=release. By default gin.DefaultWriter = os.Stdout // Logger middleware will write the logs to gin.DefaultWriter even you set with GIN_MODE=release.
// By default gin.DefaultWriter = os.Stdout
r.Use(gin.Logger()) r.Use(gin.Logger())
// Recovery middleware recovers from any panics and writes a 500 if there was one. // Recovery middleware recovers from any panics and writes a 500 if there was one.
@ -412,6 +413,27 @@ func main() {
} }
``` ```
### Output log to file
```go
func main() {
// Disable Console Color, because not need color when output log to file
gin.DisableConsoleColor()
// Create one file to save logs
f, _ := os.Create("gin.log")
// Reset gin.DefaultWriter
gin.DefaultWriter = io.MultiWriter(f)
// If need to output log to file and console at a time, please use the following code:
// gin.DefaultWriter = io.MultiWriter(f, os.Stdout)
router := gin.Default()
router.GET("/ping", func(c *gin.Context) {
c.String(200, "pong")
})
r.Run(":8080")
}
```
### Model binding and validation ### Model binding and validation
To bind a request body into a type, use model binding. We currently support binding of JSON, XML and standard form values (foo=bar&boo=baz). To bind a request body into a type, use model binding. We currently support binding of JSON, XML and standard form values (foo=bar&boo=baz).