Skip to content

Commit

Permalink
✨ v3 (feature): refactor logger middleware
Browse files Browse the repository at this point in the history
- add example for zerolog.
  • Loading branch information
efectn authored Aug 1, 2022
1 parent 6b2b1d7 commit 00718d7
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions middleware/logger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,43 @@ app.Use(logger.New(logger.Config{
}))
```

### Logging with Zerolog
```go
package main

import (
"os"

"github.com/gofiber/fiber/v3"
"github.com/gofiber/fiber/v3/middleware/logger"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)

func main() {
app := fiber.New()

log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})

app.Use(logger.New(logger.Config{LoggerFunc: func(c fiber.Ctx, data logger.LoggerData, cfg logger.Config) error {
log.Info().
Str("path", c.Path()).
Str("method", c.Method()).
Int("status", c.Response().
StatusCode()).
Msg("new request")

return nil
}}))

app.Get("/", func(c fiber.Ctx) error {
return c.SendString("test")
})

app.Listen(":3000")
}
```

## Config
```go
// Config defines the config for middleware.
Expand Down

1 comment on commit 00718d7

@ReneWerner87
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 00718d7 Previous: e49880c Ratio
Benchmark_Cache 9028 ns/op 49368 B/op 6 allocs/op 319 ns/op 16 B/op 2 allocs/op 28.30
Benchmark_Cache_AdditionalHeaders 1178 ns/op 592 B/op 9 allocs/op 422.7 ns/op 16 B/op 2 allocs/op 2.79
Benchmark_Limiter 668.1 ns/op 72 B/op 2 allocs/op 323.8 ns/op 8 B/op 1 allocs/op 2.06

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.