Skip to content

Commit

Permalink
Fix logging channel messages.
Browse files Browse the repository at this point in the history
Having '\n' character in between message field is braking SSE specification and client could not parse correctly such events

Signed-off-by: Yevhen Vydolob <[email protected]>
  • Loading branch information
evidolob committed Dec 7, 2023
1 parent 4363e80 commit f63d585
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/crc/api/events/log_stream.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package events

import (
"bytes"

"github.com/crc-org/crc/v2/pkg/crc/logging"
"github.com/r3labs/sse/v2"
"github.com/sirupsen/logrus"
Expand All @@ -23,7 +25,7 @@ func newSSEStreamHook(server *sse.Server) *streamHook {
&logrus.JSONFormatter{
TimestampFormat: "",
DisableTimestamp: false,
DisableHTMLEscape: false,
DisableHTMLEscape: true,
DataKey: "",
FieldMap: nil,
CallerPrettyfier: nil,
Expand Down Expand Up @@ -56,7 +58,10 @@ func (s *streamHook) Fire(entry *logrus.Entry) error {
return err
}

s.server.Publish(LOGS, &sse.Event{Event: []byte(LOGS), Data: line})
// remove "Line Feed"("\n") character which add was added by json.Encoder
line = bytes.TrimRight(line, "\n")

s.server.Publish(Logs, &sse.Event{Event: []byte(Logs), Data: line})
return nil
}

Expand Down

0 comments on commit f63d585

Please sign in to comment.