Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jul 20, 2023
1 parent e08040c commit aec30fc
Show file tree
Hide file tree
Showing 3 changed files with 387 additions and 11 deletions.
5 changes: 2 additions & 3 deletions contrib_versioned_docs/version-fiberzerolog_v0.x.x/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ title: 👋 Welcome
sidebar_position: 1
---

<p align="center">
<div align="center">
<img height="125" alt="Fiber" src="https://raw.githubusercontent.com/gofiber/contrib/master/.github/logo-dark.svg#gh-dark-mode-only" />
<img height="125" alt="Fiber" src="https://raw.githubusercontent.com/gofiber/contrib/master/.github/logo.svg#gh-light-mode-only" />
<br />

# Contrib

[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord)
![Test](https://github.com/gofiber/contrib/workflows/Tests/badge.svg)
Expand All @@ -17,7 +16,7 @@ sidebar_position: 1

Repository for third party middlewares with dependencies.

</p>
</div>

## 📑 Middleware Implementations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ title: Fiberzap

[Zap](https://github.com/uber-go/zap) logging support for Fiber.

### Install
## Install

This middleware supports Fiber v2.

Expand Down Expand Up @@ -65,3 +65,52 @@ func main() {
log.Fatal(app.Listen(":3000"))
}
```

## NewLogger

### Signature

```go
fiberzap.NewLogger(config ...LoggerConfig) *LoggerConfig
```

### LoggerConfig


| Property | Type | Description | Default |
|:------------|:---------------|:---------------------------------------------------------------------------------------------------------|:-------------------------------|
| CoreConfigs | `[]CoreConfig` | Define Config for zapcore | `fiberzap.LoggerConfigDefault` |
| SetLogger | `*zap.Logger` | Add custom zap logger. if not nil, `ZapOptions`, `CoreConfigs`, `SetLevel`, `SetOutput` will be ignored. | `nil` |
| ExtraKeys | `[]string` | Allow users log extra values from context. | `[]string{}` |
| ZapOptions | `[]zap.Option` | Allow users to configure the zap.Option supplied by zap. | `[]zap.Option{}` |

### Example

```go
package main

import (
"context"
"github.com/gofiber/contrib/fiberzap"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
)

func main() {
app := fiber.New()
log.SetLogger(fiberzap.NewLogger(fiberzap.LoggerConfig{
ExtraKeys: []string{"request_id"},
}))
app.Use(func(c *fiber.Ctx) error {
ctx := context.WithValue(c.UserContext(), "request_id", "123")
c.SetUserContext(ctx)
return c.Next()
})
app.Get("/", func(c *fiber.Ctx) error {
log.WithContext(c.UserContext()).Info("Hello, World!")
return c.SendString("Hello, World!")
})
log.Fatal(app.Listen(":3000"))
}
```

Loading

0 comments on commit aec30fc

Please sign in to comment.