Skip to content

Commit c1d98cb

Browse files
committed
feat: improve logging by adding context to logger events
- Add context to logger events by including `Ctx(c)` in various log level settings Signed-off-by: appleboy <appleboy.tw@gmail.com>
1 parent 1840062 commit c1d98cb

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎logger.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ func SetLogger(opts ...Option) gin.HandlerFunc {
123123

124124
switch {
125125
case c.Writer.Status() >= http.StatusBadRequest && c.Writer.Status() < http.StatusInternalServerError:
126-
evt = rl.WithLevel(cfg.clientErrorLevel)
126+
evt = rl.WithLevel(cfg.clientErrorLevel).Ctx(c)
127127
case c.Writer.Status() >= http.StatusInternalServerError:
128-
evt = rl.WithLevel(cfg.serverErrorLevel)
128+
evt = rl.WithLevel(cfg.serverErrorLevel).Ctx(c)
129129
case hasLevel:
130-
evt = rl.WithLevel(level)
130+
evt = rl.WithLevel(level).Ctx(c)
131131
default:
132-
evt = rl.WithLevel(cfg.defaultLevel)
132+
evt = rl.WithLevel(cfg.defaultLevel).Ctx(c)
133133
}
134134
evt.
135135
Int("status", c.Writer.Status()).

0 commit comments

Comments
 (0)