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

prevent string formatting in Entry.Logf when log level is not enabled #903

Merged
merged 1 commit into from Feb 10, 2019
Merged

prevent string formatting in Entry.Logf when log level is not enabled #903

merged 1 commit into from Feb 10, 2019

Conversation

gavincabbage
Copy link
Contributor

@gavincabbage gavincabbage commented Feb 6, 2019

This PR adds a conditional to Entry.Logf to avoid string formatting when the given log level is not enabled.

Actual log production is guarded against in Entry.Log, however this still results in a call to fmt.Sprintf in Entry.Logf before calling Entry.Log. The conditional is necessary in both places since both Entry.Logf and Entry.Log are public methods.

My team ran into high memory usage as a result of this "hidden" formatting when we deployed a service with lots of calls to Debugf with debug logging disabled. The change in this PR will prevent others from running into this issue in the future. It also maintains consistency with Logger.Logf by avoiding any formatting or other work if the given log level is not enabled.

@dgsb
Copy link
Collaborator

dgsb commented Feb 10, 2019

@gavincabbage thanks for your contribution

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.

None yet

2 participants