-
Notifications
You must be signed in to change notification settings - Fork 122
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]: How to do Sync on fiberzap? Is that necessary? #1160
Comments
@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 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 ( 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. |
@budiprihhastomo @Jamess-Lucass Yes you need to call That method is also known to not work inside Docker. I will update the docs. |
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:
The text was updated successfully, but these errors were encountered: