Remove single newline from the line before printing. (#2235)

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>
pull/2241/head
Peter Štibraný 6 years ago committed by GitHub
parent 4dd7a6c639
commit 9bf1130f08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      pkg/logcli/output/raw.go
  2. 16
      pkg/logcli/output/raw_test.go

@ -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
}

@ -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 {

Loading…
Cancel
Save