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

contextual logging #597

Merged
merged 1 commit into from
Sep 9, 2021
Merged

contextual logging #597

merged 1 commit into from
Sep 9, 2021

Conversation

kuritka
Copy link
Collaborator

@kuritka kuritka commented Sep 3, 2021

closes #469

  • removing duplicit error message: log.Err(err).Msgf("...(%s)",err) I'm replacing with log.Err(err).Msg("...")
  • replacing with contextual message: log.Info().Msgf("started provider (%s)",reconciler.DNSProvider.String) I'm replacing with log.Info().Str("provider", reconciler.DNSProvider.String()).Msg("started")
  • I had to extend DNSProvider with Stringer interface. added String() string function

Signed-off-by: kuritka [email protected]

 closes #469

 - removing duplicit error message: `log.Err(err).Msgf("...(%s)",err)` I'm replacing with `log.Err(err).Msg("...")`
 - replacing with contextual message: `log.Info().Msgf("started provider (%s)",reconciler.DNSProvider.String)` I'm replacing with `log.Info().Str("provider", reconciler.DNSProvider.String()).Msg("started")`
 - I had to extend DNSProvider with Stringer interface. added String() string function

Signed-off-by: kuritka <[email protected]>
}
}
return
return targets
Copy link
Member

Choose a reason for hiding this comment

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

nothing against(I actually like this style more) but why are we returning explicitly now?

Copy link
Collaborator Author

@kuritka kuritka Sep 7, 2021

Choose a reason for hiding this comment

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

Hey, good point, mee too, BUT:

golangci-lint run
controllers/providers/assistant/gslb.go:330:2: naked return in func `GetExternalTargets` with 38 lines of code (nakedret)
        return
        ^
make: *** [lint] Error 1

The linter basically says, the function is too large to have naked return (nakedret static analysis).

The function was prolonged by splitting the log messages into more lines

		log.Warn().
			Str("fqdn", fqdn).
			Str("nameserver", nameserver).
			Err(err).
			Msg("Can't resolve FQDN using nameserver")

I had three options at the end: satisfy nakedret, refactor the function into two funcs, or leave the logs on one line?

Finally I decided to satisfy nakedret.

Copy link
Member

Choose a reason for hiding this comment

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

Very clear, thanks!

Copy link
Contributor

@somaritane somaritane left a comment

Choose a reason for hiding this comment

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

@kuritka LGTM!

@kuritka kuritka merged commit 3029827 into master Sep 9, 2021
@kuritka kuritka deleted the contextual-logging branch September 9, 2021 13:41
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.

Align k8gb logging statements with zerolog best practices
4 participants