Comments (3)
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":"<<<"}
from contrib.
@ReneWerner87 thank you!
If use fiber log directly, it will be more perfect
from contrib.
@ReneWerner87 It's still a problem if use fiber log
directly when use WithContext
.
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.")
}
curl -i http://127.0.0.1:3000/ready
Output:
2023/09/25 10:56:05.581632 main.go:13: [Info] >>>
2023/09/25 10:56:05.581965 router.go:145: [Info] ready
2023/09/25 10:56:05.581970 main.go:15: [Info] <<<
from contrib.
Related Issues (20)
- π [Feature]: My (simple) SSEFiber Package HOT 1
- π€ [Question]: Could you mint a new release? HOT 3
- π€ [Question]: Swagger - Support for openapi v3?
- π [Feature]: Casbin: Allow users to use other types of Enforcers HOT 1
- π€ [Question]: otelfiber + otelmongo spans are not being grouped correctly HOT 3
- π [Bug]: i18n middleware panics HOT 17
- π [Feature]: fiberzap accepts custom fields HOT 3
- π [Bug]: Updated struct `value` in `map` after `websoket` connection. HOT 3
- π [Bug]: I have upgraded i18n/v2, but there will still be problems. HOT 15
- π [Bug]: OTeL duplicate and wrong counter metrics are generated infinitely HOT 7
- π€ [Question]: Otelfiber - How to set span status to Error on panic?
- π [Feature]: otelfiber - Propergate tracing headers in outbound response HOT 6
- π [Bug]: Swagger - not test-able (`./swagger.json` file does not exist) HOT 5
- π€ [Question]: is it possible to get the file descriptor from fiber websocket? HOT 1
- π [Bug]: error occored when import github.com/gofiber/contrib/websocket HOT 7
- π [Feature]: Otelfiber allow for manual cancellation of c.UserContext() in otelfiber.Middleware() HOT 1
- π [Bug]: FiberSentry: GetHubFromContext() never returns nil
- π [Feature]: Add golangci-lint
- π€ [Question]: fiberzerolog the banner is not printed. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from contrib.