Skip to content

Commit

Permalink
log: do not pad values longer than 40 characters (#19592)
Browse files Browse the repository at this point in the history
* log: Do not pad too long values

* log: gofmt
  • Loading branch information
nikandfor authored and karalabe committed May 20, 2019
1 parent 4cf8505 commit a541429
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions log/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import (
)

const (
timeFormat = "2006-01-02T15:04:05-0700"
termTimeFormat = "01-02|15:04:05.000"
floatFormat = 'f'
termMsgJust = 40
timeFormat = "2006-01-02T15:04:05-0700"
termTimeFormat = "01-02|15:04:05.000"
floatFormat = 'f'
termMsgJust = 40
termCtxMaxPadding = 40
)

// locationTrims are trimmed for display to avoid unwieldy log lines.
Expand Down Expand Up @@ -175,7 +176,7 @@ func logfmt(buf *bytes.Buffer, ctx []interface{}, color int, term bool) {
fieldPaddingLock.RUnlock()

length := utf8.RuneCountInString(v)
if padding < length {
if padding < length && length <= termCtxMaxPadding {
padding = length

fieldPaddingLock.Lock()
Expand All @@ -189,7 +190,7 @@ func logfmt(buf *bytes.Buffer, ctx []interface{}, color int, term bool) {
buf.WriteByte('=')
}
buf.WriteString(v)
if i < len(ctx)-2 {
if i < len(ctx)-2 && padding > length {
buf.Write(bytes.Repeat([]byte{' '}, padding-length))
}
}
Expand Down

0 comments on commit a541429

Please sign in to comment.