Update readme for showing output log to file (#1073)
* Update readme for showing output log to file * update indent
This commit is contained in:
		
							
								
								
									
										24
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								README.md
									
									
									
									
									
								
							@ -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).
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user