Skip to content

Commit

Permalink
feat: add functions to set log levels for different request statuses
Browse files Browse the repository at this point in the history
- Add a new function `WithDefaultLevel` to set the log level for requests with status code < 400
- Add a new function `WithClientErrorLevel` to set the log level for requests with status code between 400 and 499
- Add a new function `WithServerErrorLevel` to set the log level for requests with status code >= 500

Signed-off-by: appleboy <[email protected]>
  • Loading branch information
appleboy committed Feb 2, 2024
1 parent 7bec240 commit 0db81d6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,21 @@ func WithWriter(s io.Writer) Option {
})
}

// WithDefaultLevel set the log level used for request with status code < 400
func WithDefaultLevel(lvl zerolog.Level) Option {
return optionFunc(func(c *config) {
c.defaultLevel = lvl
})
}

// WithClientErrorLevel set the log level used for request with status code between 400 and 499
func WithClientErrorLevel(lvl zerolog.Level) Option {
return optionFunc(func(c *config) {
c.clientErrorLevel = lvl
})
}

// WithServerErrorLevel set the log level used for request with status code >= 500
func WithServerErrorLevel(lvl zerolog.Level) Option {
return optionFunc(func(c *config) {
c.serverErrorLevel = lvl
Expand Down

0 comments on commit 0db81d6

Please sign in to comment.