How to implement zap properly? #1437
Unanswered
tinkitwong
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have 2 questions regarding logging with zap. Appreciate comments and a healthy discussion on this! 🙏
Q1. Understand that there are ways to implement zap logger. I am having difficulty understanding which of the below (or if there are others) is an appropriate method of logging. Below are my thoughts on each method, hoping to get fact checked on this.
Pros
Cons
Q2. I have tried to implement structured logging via point 5 -- Struct Logger but having trouble with reducing duplicate code of calling logger.Sync() after creating loggers at various places (ie. controller / services layer)
// controller/foo.go
The above is an example of how I would think to implement a Struct Logger -- Pt 5. The problem I have is that I need to constantly write the below after creating loggers at the controller / service layers. I don't think I should move them into the init method as that does nothing when the NewLogger() exists upon creating the logger.
Beta Was this translation helpful? Give feedback.
All reactions