Open budiprihhastomo opened 4 months ago
@Jamess-Lucass @efectn can you help here
@budiprihhastomo Fiberzap simply uses the existing logger that has been created as part of any zap configuration. You can optionally call .Sync()
throughout your application if required. Does the question come from that fact the example provided in the fiberzap README does not contain defer logger.Sync()
which is something seen throughout the zap documentation? That hasn't been excluded from the fiberzap documentation on purpose.
https://github.com/gofiber/contrib/tree/main/fiberzap#example
func main() {
app := fiber.New()
logger, _ := zap.NewProduction()
defer logger.Sync() // <- Added this line, which is included in the zap documentation but not fiberzap.
app.Use(fiberzap.New(fiberzap.Config{
Logger: logger,
}))
app.Get("/", func (c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})
log.Fatal(app.Listen(":3000"))
}
The sync functionality is still handled outside of fiberzap, by the core zap library.
I hope this has answered your question, if this hasn't and I've misunderstood your question then please get back to me, a code example might prove helpful if that is the case.
Thank you, your code example and explanation have completed my question. Maybe this is just an idea that crossed my mind, is it possible to do this synchronization (logger.Sync()
) )when the response has arrived and been received by the client?
Maybe I thought of putting it there and making sure that the log is completely flushed. Because if we've to wait when the application got exited, I think there will be a possibility of an excess stack / something that we cannot be sure of.
So my question could also be about, is the event/hook already available on gofiber? I've searched for it but haven't found it.
Question Description
I want to use zap on my go app, but as I understand it, zap creates a Sync method, which is used to flushes the buffer into storage. And it is usually done when the application is exited or done periodically. This will ensure the log on buffer will be written to storage.
Do I need to do it? And where can I do it in fiberzap?
Code Snippet (optional)
No response
Checklist: