How to use Zap in init()? #1115
-
I have initialized Zap's SugaredLogger in
However, in one of my endpoints, I need to use zap in |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello! To use Zap in init, you'll have to initialize Zap before that init runs—probably in a module that imports it. Following that, you need to have the logger available globally. You can have your initialization logic put it in a global variable, or use Zap's global loggers. To use Zap's global loggers, call zap.ReplaceGlobals with your initialized logger. You can then access the SugaredLogger at zap.S(). Closing because answered. Feel free to re-open or create a new issue if you have more questions. Thanks! |
Beta Was this translation helpful? Give feedback.
Hello! To use Zap in init, you'll have to initialize Zap before that init runs—probably in a module that imports it.
Following that, you need to have the logger available globally. You can have your initialization logic put it in a global variable, or use Zap's global loggers.
To use Zap's global loggers, call zap.ReplaceGlobals with your initialized logger. You can then access the SugaredLogger at zap.S().
Closing because answered. Feel free to re-open or create a new issue if you have more questions. Thanks!