Skip to content

🤗 [Question]: About fiber v3 log #3763

@shangyin2024

Description

@shangyin2024

Question Description

The Fiber v3 version provides a log package. When the project is initialized, the RequestID middleware is used. Why isn't the request-id carried by default in the log.WithContext(ctx)? Currently, it looks like log.WithContext(ctx).Info and log.Info are the same.

Code Snippet (optional)

package main

import (
	"github.com/gofiber/fiber/v3"
	"github.com/gofiber/fiber/v3/log"
	"github.com/gofiber/fiber/v3/middleware/requestid"
)

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

	app.Use(requestid.New())

	app.Get("/", func(c fiber.Ctx) error {

		log.WithContext(c).Info("start...")

		// 模拟业务逻辑调用
		businessLogic(c)

		log.WithContext(c).Info("end...")

		return c.SendString("Hello, Fiber!")
	})

	log.Fatal(app.Listen(":3000"))
}
func businessLogic(c fiber.Ctx) {
	log.WithContext(c).Debug("businessLogic...")
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions