diff --git a/server/logger.go b/server/logger.go index b127096..4522fb4 100644 --- a/server/logger.go +++ b/server/logger.go @@ -9,30 +9,23 @@ import ( func Logger(ctx lib.Context) gin.HandlerFunc { return func(c *gin.Context) { - // before request // t := time.Now() - path := c.Request.URL.Path - raw := c.Request.URL.RawQuery - if raw != "" { - path = path + "?" + raw - } c.Next() - // after request msg := c.Errors.String() if msg == "" { msg = "request" } - status := c.Writer.Status() var evt *zerolog.Event - switch { - case status >= 500: + status := c.Writer.Status() + if status >= 500 { evt = logging.Error(ctx) - case status >= 400: + } else if status >= 400 { evt = logging.Warn(ctx) - default: + } else { evt = logging.Info(ctx) } - evt.Str("method", c.Request.Method).Str("path", path). + evt.Str("method", c.Request.Method). + Str("path", c.Request.URL.Path). // Dur("resp_time", time.Since(t)). Int("status", status). Str("client_ip", c.ClientIP()).Msg(msg)