From 5d6ed236488e737be72a8f39488fe20ddb311811 Mon Sep 17 00:00:00 2001 From: Kyle McCullough Date: Wed, 17 Jun 2020 20:25:48 -0500 Subject: [PATCH] writer: preserve empty events CloudWatch logs requires that events have a length > 0, so an empty event is represented as a string containing a single null byte. Previously, empty events were ignored. However, my use case cares about formatting, so I've decided to "empty" events (i.e., lines that just contain a newline character) --- writer/writer.go | 2 +- writer/writer_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/writer/writer.go b/writer/writer.go index 2519481..9af93f4 100644 --- a/writer/writer.go +++ b/writer/writer.go @@ -280,7 +280,7 @@ func (w *LogWriter) readLines() { func (w *LogWriter) appendEvent(text string) { if text == "" { - return + text = "\u0000" } w.Lock() diff --git a/writer/writer_test.go b/writer/writer_test.go index 0858922..864f46e 100644 --- a/writer/writer_test.go +++ b/writer/writer_test.go @@ -123,6 +123,33 @@ func TestWriter(t *testing.T) { }, }, }, + { + "empty lines", + newTestInput([][]byte{ + []byte("test input\n"), + []byte("\n"), + []byte("more input\n"), + []byte("\n"), + }), + Events{ + { + Message: aws.String("test input"), + Timestamp: aws.Int64(1), + }, + { + Message: aws.String("\u0000"), + Timestamp: aws.Int64(2), + }, + { + Message: aws.String("more input"), + Timestamp: aws.Int64(3), + }, + { + Message: aws.String("\u0000"), + Timestamp: aws.Int64(4), + }, + }, + }, } for _, c := range cases {