Skip to content

Commit

Permalink
Remove single newline from the line before printing. (#2235)
Browse files Browse the repository at this point in the history
Lines are printed with Println, so this avoids having extra empty line
between printed log lines.

Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
  • Loading branch information
pstibrany authored Jun 18, 2020
1 parent 4dd7a6c commit 9bf1130
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/logcli/output/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ type RawOutput struct {

// Format a log entry as is
func (o *RawOutput) Format(ts time.Time, lbls loghttp.LabelSet, maxLabelsLen int, line string) string {
if len(line) > 0 && line[len(line)-1] == '\n' {
line = line[:len(line)-1]
}
return line
}
16 changes: 16 additions & 0 deletions pkg/logcli/output/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ func TestRawOutput_Format(t *testing.T) {
"Hello world",
"Hello world",
},
"line with single newline at the end": {
&LogOutputOptions{Timezone: time.UTC, NoLabels: false},
timestamp,
someLabels,
0,
"Hello world\n",
"Hello world",
},
"line with multiple newlines at the end": {
&LogOutputOptions{Timezone: time.UTC, NoLabels: false},
timestamp,
someLabels,
0,
"Hello world\n\n\n",
"Hello world\n\n",
},
}

for testName, testData := range tests {
Expand Down

0 comments on commit 9bf1130

Please sign in to comment.