Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fiberzap: Adapter for fiber/log #666

Merged
merged 4 commits into from
Jul 20, 2023
Merged

Fiberzap: Adapter for fiber/log #666

merged 4 commits into from
Jul 20, 2023

Conversation

Skyenought
Copy link
Member

This update is to adapt the fiberlog package

Example

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!")
		log.Infow("Hello, World!", "test", "custom")
		log.Infof("Hello, %s", "World!")
		return c.SendString("Hello, World!")
	})
	log.Fatal(app.Listen(":3000"))
}

result:

{"level":"info","ts":1688009051.6242049,"msg":"Hello, World!","request_id":"123"}
{"level":"info","ts":1688009051.6242645,"msg":"Hello, World!","test":"custom"}
{"level":"info","ts":1688009051.6242726,"msg":"Hello, World!"}

fiberzap/go.mod Outdated Show resolved Hide resolved
@ReneWerner87
Copy link
Member

ReneWerner87 commented Jul 3, 2023

  • everything looks good, we are just waiting for the next fiber release

@gaby
Copy link
Member

gaby commented Jul 16, 2023

@Skyenought The version of Fiber is out with support for Logger interface. You can rebase/update the PR now 😁

@ReneWerner87
Copy link
Member

either you change the go.mod yourself or wait for dependabot and update with the master afterwards

@gaby
Copy link
Member

gaby commented Jul 18, 2023

@Skyenought Small conflict with main

fiberzap/go.mod Outdated Show resolved Hide resolved
@gaby gaby requested a review from ReneWerner87 July 18, 2023 11:18
@ReneWerner87 ReneWerner87 merged commit 2150889 into gofiber:main Jul 20, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✏️ Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants