From 9fd08583f21b999ca3222ec02b55df07022f8ed4 Mon Sep 17 00:00:00 2001 From: Dominik Rosiek Date: Wed, 7 Jul 2021 08:35:41 +0200 Subject: [PATCH] fix(multiline): use proper advance and strip new line whitespaces from beginning of log Signed-off-by: Dominik Rosiek --- operator/helper/multiline.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/operator/helper/multiline.go b/operator/helper/multiline.go index 5febc984..7aed4e2a 100644 --- a/operator/helper/multiline.go +++ b/operator/helper/multiline.go @@ -80,7 +80,7 @@ func NewLineStartSplitFunc(re *regexp.Regexp, flushAtEOF bool) bufio.SplitFunc { // Flush if no more data is expected if len(data) != 0 && atEOF && flushAtEOF { token = trimWhitespaces(data) - advance = len(token) + advance = len(data) return } return 0, nil, nil // read more data and try again. @@ -103,7 +103,7 @@ func NewLineStartSplitFunc(re *regexp.Regexp, flushAtEOF bool) bufio.SplitFunc { // Flush if no more data is expected if atEOF && flushAtEOF { token = trimWhitespaces(data) - advance = len(token) + advance = len(data) return } @@ -130,7 +130,7 @@ func NewLineEndSplitFunc(re *regexp.Regexp, flushAtEOF bool) bufio.SplitFunc { // Flush if no more data is expected if len(data) != 0 && atEOF && flushAtEOF { token = trimWhitespaces(data) - advance = len(token) + advance = len(data) return } return 0, nil, nil // read more data and try again @@ -175,7 +175,7 @@ func NewNewlineSplitFunc(encoding encoding.Encoding, flushAtEOF bool) (bufio.Spl // Flush if no more data is expected if atEOF && flushAtEOF { token = trimWhitespaces(data) - advance = len(token) + advance = len(data) return } @@ -197,5 +197,8 @@ func encodedCarriageReturn(encoding encoding.Encoding) ([]byte, error) { } func trimWhitespaces(data []byte) []byte { - return bytes.TrimRight(data, "\r\n\t ") + // TrimLeft to strip EOF whitespaces in case of using $ in regex + // For some reason newline and carriage return are being moved to beginning of next log + // TrimRight to strip all whitespaces from the end of log + return bytes.TrimLeft(bytes.TrimRight(data, "\r\n\t "), "\r\n") }