Skip to content
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

how to use zap.field? #32

Closed
wuyunhua1987 opened this issue Jun 4, 2023 · 5 comments
Closed

how to use zap.field? #32

wuyunhua1987 opened this issue Jun 4, 2023 · 5 comments
Labels
question Further information is requested

Comments

@wuyunhua1987
Copy link

eg: zap.String("name", "john"), zap.Int("age", 18), then json output likes this: {"name": "john", "age": 18}

@li-jin-gou
Copy link
Contributor

Not supported, complex log printing is recommended using the native zap

@li-jin-gou li-jin-gou added the question Further information is requested label Jun 4, 2023
@li-jin-gou
Copy link
Contributor

However, it is recommended that hlog be injected into the zap implementation as well to ensure that both framework logs and business logs can be seen.

@wuyunhua1987
Copy link
Author

what about logger.Infow? this is what i need but it hasn't been implemented

@li-jin-gou
Copy link
Contributor

what about logger.Infow? this is what i need but it hasn't been implemented

not support and i recommend using zap directly, you can use hlog.SetLogger to inject zap and ensure that the framework logs are collected by you as well.

@Skyenought
Copy link
Member

@wuyunhua1987 现在 zap 支持导出原生 logger, 以支持复杂操作

logger := hertzap.NewLogger()
hlog.SetLogger(logger)

h.GET("/hello", func(ctx context.Context, c *app.RequestContext) {
	logger.Logger().Info("Hello, World!", zap.Int("status", c.Response().StatusCode()))
	c.String(consts.StatusOK, "Hello hertz!")
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants