From e6ee8f97453285fc71242428d51505b8f25232bb Mon Sep 17 00:00:00 2001 From: Ankit Deshpande Date: Sat, 23 Mar 2019 02:49:47 +0530 Subject: [PATCH] Init hostname only once --- logger.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/logger.go b/logger.go index eff5c05..d97d4b7 100644 --- a/logger.go +++ b/logger.go @@ -20,6 +20,10 @@ var timeFormat = "02/Jan/2006:15:04:05 -0700" // Logger is the logrus logger handler func Logger(log *logrus.Logger) gin.HandlerFunc { + hostname, err := os.Hostname() + if err != nil { + hostname = "unknow" + } return func(c *gin.Context) { // other handler can change c.Path so: path := c.Request.URL.Path @@ -31,10 +35,6 @@ func Logger(log *logrus.Logger) gin.HandlerFunc { clientIP := c.ClientIP() clientUserAgent := c.Request.UserAgent() referer := c.Request.Referer() - hostname, err := os.Hostname() - if err != nil { - hostname = "unknow" - } dataLength := c.Writer.Size() if dataLength < 0 { dataLength = 0