You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to log a custom header x-request-id in fiber access log using fiberzerolog. but the value is empty when shown in the console.
curl -X GET http://localhost:3000 -H "X-Request-Id: abc123"
Code Snippet (optional)
package main
import (
"os""time""github.com/gofiber/fiber/v2""github.com/rs/zerolog"
)
funcmain() {
// Initialize the loggerloggger:=zerolog.New(os.Stderr).
With().
Timestamp().
Logger().
Output(zerolog.ConsoleWriter{
Out: os.Stderr,
TimeLocation: time.UTC,
TimeFormat: "02-Jan-2006 15:04:05",
}).
Level(zerolog.DebugLevel)
// Create a new Fiber appapp:=fiber.New()
app.Use(fiberzerolog.New(fiberzerolog.Config{
Logger: &loggger,
Fields: []string{"referer", "ip", "ips", "method", "url", "ua", "latency", "status", "bytesSent", "bytesReceived", "route", "error", "reqHeader:X-Request-Id"},
SkipURIs: []string{"/internal/metrics", "/internal/health/live", "/internal/health/ready", "/internal/health/startup"},
}))
// Define a routeapp.Get("/", func(c*fiber.Ctx) error {
// Use Fiber's Locals to set custom context valuesc.Locals("test", "test")
// create logger with subsystem for each modules and utilize it in the functons// https://gitlab.grootan.com/qlikverify/development/ezto-gateway/-/blob/master/lib/middleware/logger.go?ref_type=heads// Retrieve and log the value from the contextvalue:=c.Locals("test")
loggger.Info().Msgf("Retrieved value from context: %s", value)
// Respond to the clientreturnc.SendString("Hello, World!")
})
// Start the serveriferr:=app.Listen(":3000"); err!=nil {
loggger.Fatal().Err(err).Msg("Fiber app error")
}
}
@ReneWerner87 thanks. the middlware already support request id but it need the requestid middleware to work. passing just the request id header is not working
Question Description
I want to log a custom header x-request-id in fiber access log using fiberzerolog. but the value is empty when shown in the console.
curl -X GET http://localhost:3000 -H "X-Request-Id: abc123"
Code Snippet (optional)
Checklist:
The text was updated successfully, but these errors were encountered: