Skip to content

Comments

Fix trailing space#591

Merged
dmathieu merged 2 commits intomasterfrom
fix_trailing_space
Jul 22, 2017
Merged

Fix trailing space#591
dmathieu merged 2 commits intomasterfrom
fix_trailing_space

Conversation

@dmathieu
Copy link
Contributor

Closes #99

@dmathieu dmathieu requested a review from seiffert July 21, 2017 14:17
}

func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

❤️

func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) {

if b.String() != "" {
b.WriteByte(' ')
Copy link
Collaborator

Choose a reason for hiding this comment

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

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

@dmathieu dmathieu merged commit 3eef8ce into master Jul 22, 2017
@dmathieu dmathieu deleted the fix_trailing_space branch July 22, 2017 11:39

func (f *TextFormatter) appendKeyValue(b *bytes.Buffer, key string, value interface{}) {

if b.String() != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Do you want to open a PR?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if I have time today, but it would be good to get this fixed.

RenovZ pushed a commit to RenovZ/logrus that referenced this pull request Mar 25, 2022
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.

3 participants