Skip to content

Commit

Permalink
use string builder
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdarkdragon committed Dec 3, 2021
1 parent 117db66 commit 9dc806d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions clog/clog.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,22 @@ func messageFromContext(ctx context.Context) string {
if cmap == nil {
return ""
}
var parts []string
var sb strings.Builder
for _, key := range stdKeysOrder {
if val, ok := cmap[key]; ok {
parts = append(parts, key+"="+val)
sb.WriteString(key)
sb.WriteString("=")
sb.WriteString(val)
}
}
for key, val := range cmap {
if _, ok := stdKeys[key]; !ok {
parts = append(parts, key+"="+val)
sb.WriteString(key)
sb.WriteString("=")
sb.WriteString(val)
}
}
return strings.Join(parts, " ")
return sb.String()
}

func formatMessage(ctx context.Context, format string, args ...interface{}) string {
Expand Down

0 comments on commit 9dc806d

Please sign in to comment.