Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion v2/slogger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ type Log struct {
MessageFmt string
Args []interface{}
Context *Context

// Appendages to evaluate a message only once
message string
Copy link
Copy Markdown

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...

evalMsgOnce sync.Once
}

func SimpleLog(prefix string, level Level, errorCode ErrorCode, callerSkip int, messageFmt string, args ...interface{}) *Log {
Expand Down Expand Up @@ -101,7 +105,10 @@ func getTruncatedMessage(old string) string {
}

func (self *Log) Message() string {
return getTruncatedMessage(fmt.Sprintf(self.MessageFmt, self.Args...))
self.evalMsgOnce.Do(func() {
self.message = getTruncatedMessage(fmt.Sprintf(self.MessageFmt, self.Args...))
})
return self.message
}

type Logger struct {
Expand Down