Skip to content

Commit

Permalink
make sure no trailing spaces
Browse files Browse the repository at this point in the history
Closes #99

Signed-off-by: Derek Che <drc@yahoo-inc.com>
  • Loading branch information
Derek Che committed Jan 4, 2015
1 parent d2f9ffa commit 2d4e034
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions text_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ func (f *TextFormatter) Format(entry *Entry) ([]byte, error) {
}
}

b.WriteByte('\n')
return b.Bytes(), nil
// remove trailing space
byts := b.Bytes()
byts = bytes.TrimSpace(byts)
byts = append(byts, '\n')

return byts, nil
}

func printColored(b *bytes.Buffer, entry *Entry, keys []string) {
Expand Down
11 changes: 11 additions & 0 deletions text_formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ func TestQuoting(t *testing.T) {
checkQuoting(false, errors.New("invalid"))
checkQuoting(true, errors.New("invalid argument"))
}

func TestTextPrint(t *testing.T) {
tf := &TextFormatter{DisableColors: true}
byts, _ := tf.Format(&Entry{Message: "msg content"})

// make sure no trailing spaces
if string(byts) !=
"time=\"0001-01-01T00:00:00Z\" level=panic msg=\"msg content\"\n" {
t.Errorf("not expected: %q", string(byts))
}
}

0 comments on commit 2d4e034

Please sign in to comment.