Skip to content

Commit

Permalink
fix: correct a data race
Browse files Browse the repository at this point in the history
  • Loading branch information
mgabeler-lee-6rs committed Dec 8, 2023
1 parent efa31a5 commit b9be8af
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ func SetLogger(opts ...Option) gin.HandlerFunc {
Timestamp().
Logger()
return func(c *gin.Context) {
rl := l
if cfg.logger != nil {
l = cfg.logger(c, l)
rl = cfg.logger(c, l)
}

start := time.Now()
Expand Down Expand Up @@ -112,11 +113,11 @@ func SetLogger(opts ...Option) gin.HandlerFunc {
var evt *zerolog.Event
switch {
case c.Writer.Status() >= http.StatusBadRequest && c.Writer.Status() < http.StatusInternalServerError:
evt = l.WithLevel(cfg.clientErrorLevel)
evt = rl.WithLevel(cfg.clientErrorLevel)
case c.Writer.Status() >= http.StatusInternalServerError:
evt = l.WithLevel(cfg.serverErrorLevel)
evt = rl.WithLevel(cfg.serverErrorLevel)
default:
evt = l.WithLevel(cfg.defaultLevel)
evt = rl.WithLevel(cfg.defaultLevel)
}
evt.
Int("status", c.Writer.Status()).
Expand Down

0 comments on commit b9be8af

Please sign in to comment.