Conversation
So we don't have a trailing space at the end of each log line
| } | ||
|
|
||
| func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) { | ||
|
|
| func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) { | ||
|
|
||
| if b.String() != "" { | ||
| b.WriteByte(' ') |
There was a problem hiding this comment.
I wonder whether the buffer could be a string slice (then we could just use strings.Join()). However this refactoring is out of scope of this PR an your change definitely does the job!
There was a problem hiding this comment.
We apparently allow it to be any buffer (the client can specify it). So it doesn't seem we could do that without breaking the api.
|
|
||
| func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) { | ||
|
|
||
| if b.String() != "" { |
There was a problem hiding this comment.
This is going to cost allocation of the whole buffer. If this is used in a loop, a string will be created when appending each value, generating a lot of garbage for every log message. It would be better to test the length of the buffer.
There was a problem hiding this comment.
Good idea. Do you want to open a PR?
There was a problem hiding this comment.
I'm not sure if I have time today, but it would be good to get this fixed.
Fix trailing space
Closes #99