-
Notifications
You must be signed in to change notification settings - Fork 120
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
🤗 [Question]: When use fiberzap
with WithContext
, caller maybe not show properly. How do I change it?
#791
Labels
🤔 Question
Further information is requested
Comments
without the fiber logger wrapper it is working package main
import (
"github.com/gofiber/contrib/fiberzap/v2"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func main() {
//setup.Init()
app := fiber.New()
zap := fiberzap.NewLogger(fiberzap.LoggerConfig{
ZapOptions: []zap.Option{
zap.AddCaller(),
zap.AddCallerSkip(2),
zap.AddStacktrace(zapcore.PanicLevel),
},
})
app.Get("/ready", func(c *fiber.Ctx) error {
zap.Info(">>>")
zap.WithContext(c.UserContext()).Info("ready")
zap.Info("<<<")
return c.SendString("ready")
})
err := app.Listen(":3000")
if err != nil {
log.Error(err)
return
}
} {"level":"info","ts":1695285876.640757,"caller":"testGo/main.go:23","msg":">>>"}
{"level":"info","ts":1695285876.6409469,"caller":"testGo/main.go:24","msg":"ready"}
{"level":"info","ts":1695285876.640969,"caller":"testGo/main.go:25","msg":"<<<"} @Skyenought do you have an idea, why the wrapper function is shifting the outside caller level? with skip 2 log.SetLogger(fiberzap.NewLogger(fiberzap.LoggerConfig{
ZapOptions: []zap.Option{
zap.AddCaller(),
zap.AddCallerSkip(2),
zap.AddStacktrace(zapcore.PanicLevel),
},
}))
app.Get("/ready", func(c *fiber.Ctx) error {
log.Info(">>>")
log.WithContext(c.UserContext()).Info("ready")
log.Info("<<<")
return c.SendString("ready")
}) {"level":"info","ts":1695286200.526693,"caller":"log/fiberlog.go:25","msg":">>>"}
{"level":"info","ts":1695286200.526879,"caller":"testGo/main.go:24","msg":"ready"}
{"level":"info","ts":1695286200.526884,"caller":"log/fiberlog.go:25","msg":"<<<"} |
@ReneWerner87 thank you! |
@ReneWerner87 It's still a problem if use package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
)
func main() {
//setup.Init()
app := fiber.New()
app.Get("/ready", func(c *fiber.Ctx) error {
log.Info(">>>")
log.WithContext(c.UserContext()).Info("ready")
log.Info("<<<")
return c.SendString("ready")
})
err := app.Listen(":3000")
if err != nil {
log.Error(err)
return
}
log.Info("Exit.")
}
|
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Question Description
Run the code snippet, and the logging is as follows
caller is
v2@v2.49.2/router.go:145
, but it isbackend2/main.go:24
actuallyCode Snippet (optional)
Checklist:
The text was updated successfully, but these errors were encountered: