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

Evaluate message formatting only once while formatting the log #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ramasai1
Copy link
Contributor

@ramasai1 ramasai1 commented Nov 11, 2022

log.Message() can be called multiple times after the Log object has been constructed, and each time it'll print the formatted over and over again. This PR introduces a way in which evaluation happens once, and the formatted log is stored in the Log and is returned without any cost.

QA: ./run-tests shows everything in v2 passing.

cc @dunkyboy

@@ -36,6 +36,10 @@ type Log struct {
MessageFmt string
Args []interface{}
Context *Context

// Appendages to evaluate a message only once
message string

Choose a reason for hiding this comment

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

What is the lifecycle of a Log struct? We've now ~doubled the effective size of it, assuming MessageFmt (and now message) is long compared to the other fields...

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.

2 participants