Skip to content

How to use Zap in init()? #1115

Answered by abhinav
albert-csms asked this question in Q&A
Discussion options

You must be logged in to vote

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!

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by abhinav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants
Converted from issue

This discussion was converted from issue #1030 on June 15, 2022 12:49.