forked from mirror/gin-logrus
Init hostname only once
This commit is contained in:
parent
5d05462a6e
commit
e6ee8f9745
|
@ -20,6 +20,10 @@ var timeFormat = "02/Jan/2006:15:04:05 -0700"
|
||||||
|
|
||||||
// Logger is the logrus logger handler
|
// Logger is the logrus logger handler
|
||||||
func Logger(log *logrus.Logger) gin.HandlerFunc {
|
func Logger(log *logrus.Logger) gin.HandlerFunc {
|
||||||
|
hostname, err := os.Hostname()
|
||||||
|
if err != nil {
|
||||||
|
hostname = "unknow"
|
||||||
|
}
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
// other handler can change c.Path so:
|
// other handler can change c.Path so:
|
||||||
path := c.Request.URL.Path
|
path := c.Request.URL.Path
|
||||||
|
@ -31,10 +35,6 @@ func Logger(log *logrus.Logger) gin.HandlerFunc {
|
||||||
clientIP := c.ClientIP()
|
clientIP := c.ClientIP()
|
||||||
clientUserAgent := c.Request.UserAgent()
|
clientUserAgent := c.Request.UserAgent()
|
||||||
referer := c.Request.Referer()
|
referer := c.Request.Referer()
|
||||||
hostname, err := os.Hostname()
|
|
||||||
if err != nil {
|
|
||||||
hostname = "unknow"
|
|
||||||
}
|
|
||||||
dataLength := c.Writer.Size()
|
dataLength := c.Writer.Size()
|
||||||
if dataLength < 0 {
|
if dataLength < 0 {
|
||||||
dataLength = 0
|
dataLength = 0
|
||||||
|
|
Loading…
Reference in New Issue