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

leader: call argument eval for log formatting lazily #10682

Merged
merged 1 commit into from
Jun 2, 2021

Conversation

tgross
Copy link
Member

@tgross tgross commented Jun 2, 2021

Arguments to our logger's various write methods are evaluated eagerly, so method calls in log parameters will always be called, regardless of log level. Move some logger messages to the logger's Fmt method so that GoString is evaluated lazily instead.

Noticed this while working on an unrelated bug, where it'll matter more as it's in a hot code path. Realistically if we're on this code path we're going to evaluate these anyways because our worst log level is warn, but given that we have a habit of copy-and-pasting code around it's better to "always do it right".

https://play.golang.org/p/azP_04QmQGY gives a demonstration of how the lazy evaluation works out.

Arguments to our logger's various write methods are evaluated eagerly, so
method calls in log parameters will always be called, regardless of log
level. Move some logger messages to the logger's `Fmt` method so that
`GoString` is evaluated lazily instead.
@tgross tgross requested review from shoenig and isabeldepapel June 2, 2021 13:40
Copy link
Contributor

@shoenig shoenig left a comment

Choose a reason for hiding this comment

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

LGTM

@tgross tgross merged commit da15c0f into main Jun 2, 2021
@tgross tgross deleted the b-lazy-eval-logging branch June 2, 2021 13:59
@tgross tgross added this to the 1.1.1 milestone Jun 3, 2021
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants