Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
blakerouse committed Jun 11, 2024
1 parent 2e09c33 commit 0901636
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/component/runtime/log_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func (r *logWriter) Write(p []byte) (int, error) {
continue
}
str := strings.TrimSpace(string(line))
if len(str) == 0 {
// empty line after trim
continue
}
// try to parse line as JSON
if str[0] == '{' && r.handleJSON(str) {
// handled as JSON
Expand Down
27 changes: 27 additions & 0 deletions pkg/component/runtime/log_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,33 @@ func TestLogWriter(t *testing.T) {
},
},
},
{
Name: "multi empty text line",
LogLevel: zapcore.InfoLevel,
LogSource: logSourceStdout,
Lines: []string{
"simple written line\r\n",
"\r\n", // empty line
" \r\n", // empty line with space
"another line\n",
},
Wrote: []wrote{
{
entry: zapcore.Entry{
Level: zapcore.InfoLevel,
Time: time.Time{},
Message: "simple written line",
},
},
{
entry: zapcore.Entry{
Level: zapcore.InfoLevel,
Time: time.Time{},
Message: "another line",
},
},
},
},
{
Name: "json log line split",
LogLevel: zapcore.DebugLevel,
Expand Down

0 comments on commit 0901636

Please sign in to comment.