diff --git a/pkg/logcli/output/raw.go b/pkg/logcli/output/raw.go index 8a5b9b9eadbe..0934ddda97a1 100644 --- a/pkg/logcli/output/raw.go +++ b/pkg/logcli/output/raw.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 } diff --git a/pkg/logcli/output/raw_test.go b/pkg/logcli/output/raw_test.go index 358fecd0d2dc..4c280ac3c269 100644 --- a/pkg/logcli/output/raw_test.go +++ b/pkg/logcli/output/raw_test.go @@ -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 {