@@ -139,39 +139,28 @@ func (h *Server) rateLimit(c *gin.Context) {
139139}
140140
141141func (h * Server ) attachLogger (c * gin.Context ) {
142- path := c . Request . URL . Path
143-
144- fields := make ([]zapcore. Field , 0 , 9 )
142+ start := time . Now ()
143+ c . Next ()
144+ latency := time . Since ( start )
145145
146+ fields := make ([]zapcore.Field , 0 , 7 )
146147 fields = append (fields ,
147148 zap .Int ("status" , c .Writer .Status ()),
148149 zap .String ("method" , c .Request .Method ),
149- zap .String ("path" , path ),
150150 zap .String ("query" , c .Request .URL .RawQuery ),
151151 zap .String ("ip" , c .ClientIP ()),
152152 zap .String ("user-agent" , c .Request .UserAgent ()),
153- )
154-
155- start := time .Now ().UTC ()
156- c .Next ()
157- end := time .Now ().UTC ()
158- latency := end .Sub (start )
159-
160- fields = append (fields ,
161153 zap .Duration ("latency" , latency ),
162- zap .String ("time" , end .Format ("" )),
163154 )
164155
165- if len (c .Errors ) > 0 {
156+ path := c .Request .URL .Path
157+ switch {
158+ case len (c .Errors ) > 0 :
166159 errs := make ([]error , 0 , len (c .Errors ))
167160 for _ , e := range c .Errors {
168161 errs = append (errs , e )
169162 }
170163 fields = append (fields , zap .Errors ("errs" , errs ))
171- }
172-
173- switch {
174- case len (c .Errors ) > 0 :
175164 h .lg .Warn (path , fields ... )
176165 default :
177166 h .lg .Debug (path , fields ... )
0 commit comments