Skip to content

Commit

Permalink
writer: preserve empty events
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
kylemcc committed Jun 18, 2020
1 parent 4759b0f commit 5d6ed23
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion writer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func (w *LogWriter) readLines() {

func (w *LogWriter) appendEvent(text string) {
if text == "" {
return
text = "\u0000"
}

w.Lock()
Expand Down
27 changes: 27 additions & 0 deletions writer/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5d6ed23

Please sign in to comment.