-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update newest doc from gin readme (#49)
- Loading branch information
Showing
18 changed files
with
146 additions
and
2,044 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# This viminfo file was generated by Vim 8.0. | ||
# You may edit it if you're careful! | ||
|
||
# Viminfo version | ||
|1,4 | ||
|
||
# Value of 'encoding' when this file was written | ||
*encoding=utf-8 | ||
|
||
|
||
# hlsearch on (H) or off (h): | ||
~h | ||
# Command Line History (newest to oldest): | ||
|
||
# Search String History (newest to oldest): | ||
|
||
# Expression History (newest to oldest): | ||
|
||
# Input Line History (newest to oldest): | ||
|
||
# Debug Line History (newest to oldest): | ||
|
||
# Registers: | ||
|
||
# File marks: | ||
'0 1 0 ~/go/src/github.com/gin-gonic/website/content/en/docs/examples/grep | ||
|4,48,1,0,1551702651,"~/go/src/github.com/gin-gonic/website/content/en/docs/examples/grep" | ||
|
||
# Jumplist (newest first): | ||
-' 1 0 ~/go/src/github.com/gin-gonic/website/content/en/docs/examples/grep | ||
|4,39,1,0,1551702651,"~/go/src/github.com/gin-gonic/website/content/en/docs/examples/grep" | ||
|
||
# History of marks within files (newest to oldest): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
content/en/docs/examples/controlling-log-output-coloring.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
title: "Controlling Log output coloring" | ||
draft: false | ||
--- | ||
|
||
By default, logs output on console should be colorized depending on the detected TTY. | ||
|
||
Never colorize logs: | ||
|
||
```go | ||
func main() { | ||
// Disable log's color | ||
gin.DisableConsoleColor() | ||
|
||
// Creates a gin router with default middleware: | ||
// logger and recovery (crash-free) middleware | ||
router := gin.Default() | ||
|
||
router.GET("/ping", func(c *gin.Context) { | ||
c.String(200, "pong") | ||
}) | ||
|
||
router.Run(":8080") | ||
} | ||
``` | ||
|
||
Always colorize logs: | ||
|
||
```go | ||
func main() { | ||
// Force log's color | ||
gin.ForceConsoleColor() | ||
|
||
// Creates a gin router with default middleware: | ||
// logger and recovery (crash-free) middleware | ||
router := gin.Default() | ||
|
||
router.GET("/ping", func(c *gin.Context) { | ||
c.String(200, "pong") | ||
}) | ||
|
||
router.Run(":8080") | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
title: "Custom log file" | ||
draft: false | ||
--- | ||
|
||
For example: | ||
|
||
```go | ||
func main() { | ||
router := gin.New() | ||
// LoggerWithFormatter middleware will write the logs to gin.DefaultWriter | ||
// By default gin.DefaultWriter = os.Stdout | ||
router.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string { | ||
// your custom format | ||
return fmt.Sprintf("%s - [%s] \"%s %s %s %d %s \"%s\" %s\"\n", | ||
param.ClientIP, | ||
param.TimeStamp.Format(time.RFC1123), | ||
param.Method, | ||
param.Path, | ||
param.Request.Proto, | ||
param.StatusCode, | ||
param.Latency, | ||
param.Request.UserAgent(), | ||
param.ErrorMessage, | ||
) | ||
})) | ||
router.Use(gin.Recovery()) | ||
router.GET("/ping", func(c *gin.Context) { | ||
c.String(200, "pong") | ||
}) | ||
router.Run(":8080") | ||
} | ||
``` | ||
|
||
**Sample Output** | ||
``` | ||
::1 - [Fri, 07 Dec 2018 17:04:38 JST] "GET /ping HTTP/1.1 200 122.767µs "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36" " | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.