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

fix: iter would no longer be inited every time in the loop #565

Closed
wants to merge 1 commit into from

Conversation

wrapupc
Copy link

@wrapupc wrapupc commented Apr 12, 2023

fix: iter would no longer be inited every time in the loop

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

Verification

I've used this code in my project, and the log looks good now

@google-cla
Copy link

google-cla bot commented Apr 12, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Collaborator

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks <3

One nit, otherwise LGTM - also CLA is required. Thanks!!

@@ -17,10 +17,10 @@ import (
func InterceptorLogger(l *zap.Logger) logging.Logger {
return logging.LoggerFunc(func(ctx context.Context, lvl logging.Level, msg string, fields ...any) {
f := make([]zap.Field, 0, len(fields)/2)
iter := logging.Fields(fields).Iterator()
for i := 0; i < len(fields); i += 2 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be simplified further, similar to https://github.com/grpc-ecosystem/go-grpc-middleware/blob/main/interceptors/logging/examples/logrus/example_test.go#L21

I messed this up 🙃 Can we double check other examples too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually needs to be for iter.Next(). This issue seems to be present on all the examples.

@bwplotka
Copy link
Collaborator

Fixes #559

@bwplotka
Copy link
Collaborator

Also we need tests, but we can do them in later PRs (or here) - added issue to track this: #567

@chancez
Copy link
Contributor

chancez commented Jun 9, 2023

This should be fixed via #588 so I think this can be closed.

@bwplotka
Copy link
Collaborator

Thanks!

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

Successfully merging this pull request may close these issues.

5 participants