Skip to content

Commit

Permalink
feat: improve logging by adding context to logger events
Browse files Browse the repository at this point in the history
- Add context to logger events by including `Ctx(c)` in various log level settings

Signed-off-by: appleboy <[email protected]>
  • Loading branch information
appleboy committed Nov 8, 2024
1 parent 1840062 commit c1d98cb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ func SetLogger(opts ...Option) gin.HandlerFunc {

switch {
case c.Writer.Status() >= http.StatusBadRequest && c.Writer.Status() < http.StatusInternalServerError:
evt = rl.WithLevel(cfg.clientErrorLevel)
evt = rl.WithLevel(cfg.clientErrorLevel).Ctx(c)
case c.Writer.Status() >= http.StatusInternalServerError:
evt = rl.WithLevel(cfg.serverErrorLevel)
evt = rl.WithLevel(cfg.serverErrorLevel).Ctx(c)
case hasLevel:
evt = rl.WithLevel(level)
evt = rl.WithLevel(level).Ctx(c)
default:
evt = rl.WithLevel(cfg.defaultLevel)
evt = rl.WithLevel(cfg.defaultLevel).Ctx(c)
}
evt.
Int("status", c.Writer.Status()).
Expand Down

0 comments on commit c1d98cb

Please sign in to comment.