mirror of https://github.com/gin-gonic/gin.git
Merge branch 'master' of github.com:se77en/gin into develop
This commit is contained in:
commit
e10ed9482d
27
logger.go
27
logger.go
|
@ -31,6 +31,9 @@ var (
|
||||||
white = string([]byte{27, 91, 57, 48, 59, 52, 55, 109})
|
white = string([]byte{27, 91, 57, 48, 59, 52, 55, 109})
|
||||||
yellow = string([]byte{27, 91, 57, 55, 59, 52, 51, 109})
|
yellow = string([]byte{27, 91, 57, 55, 59, 52, 51, 109})
|
||||||
red = string([]byte{27, 91, 57, 55, 59, 52, 49, 109})
|
red = string([]byte{27, 91, 57, 55, 59, 52, 49, 109})
|
||||||
|
blue = string([]byte{27, 91, 57, 55, 59, 52, 52, 109})
|
||||||
|
magenta = string([]byte{27, 91, 57, 55, 59, 52, 53, 109})
|
||||||
|
cyan = string([]byte{27, 91, 57, 55, 59, 52, 54, 109})
|
||||||
reset = string([]byte{27, 91, 48, 109})
|
reset = string([]byte{27, 91, 48, 109})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -68,14 +71,34 @@ func Logger() HandlerFunc {
|
||||||
default:
|
default:
|
||||||
color = red
|
color = red
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var methodColor string
|
||||||
|
method := c.Request.Method
|
||||||
|
switch {
|
||||||
|
case method == "GET":
|
||||||
|
methodColor = blue
|
||||||
|
case method == "POST":
|
||||||
|
methodColor = cyan
|
||||||
|
case method == "PUT":
|
||||||
|
methodColor = yellow
|
||||||
|
case method == "DELETE":
|
||||||
|
methodColor = red
|
||||||
|
case method == "PATCH":
|
||||||
|
methodColor = green
|
||||||
|
case method == "HEAD":
|
||||||
|
methodColor = magenta
|
||||||
|
case method == "OPTIONS":
|
||||||
|
methodColor = white
|
||||||
|
}
|
||||||
end := time.Now()
|
end := time.Now()
|
||||||
latency := end.Sub(start)
|
latency := end.Sub(start)
|
||||||
stdlogger.Printf("[GIN] %v |%s %3d %s| %12v | %s %4s %s\n%s",
|
stdlogger.Printf("[GIN] %v |%s %3d %s| %12v | %s |%s %-7s %s| %s\n%s",
|
||||||
end.Format("2006/01/02 - 15:04:05"),
|
end.Format("2006/01/02 - 15:04:05"),
|
||||||
color, code, reset,
|
color, code, reset,
|
||||||
latency,
|
latency,
|
||||||
requester,
|
requester,
|
||||||
c.Request.Method, c.Request.URL.Path,
|
methodColor, method, reset,
|
||||||
|
c.Request.URL.Path,
|
||||||
c.Errors.String(),
|
c.Errors.String(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue