Skip to content

Commit 54df54b

Browse files
committed
Fix logging channel messages.
Having '\n' character in between message field is braking SSE specification and client could not parse correctly such events Signed-off-by: Yevhen Vydolob <yvydolob@redhat.com>
1 parent 8da3a23 commit 54df54b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkg/crc/api/events/log_stream.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package events
22

33
import (
4+
"bytes"
5+
46
"github.com/crc-org/crc/v2/pkg/crc/logging"
57
"github.com/r3labs/sse/v2"
68
"github.com/sirupsen/logrus"
@@ -23,7 +25,7 @@ func newSSEStreamHook(server *sse.Server) *streamHook {
2325
&logrus.JSONFormatter{
2426
TimestampFormat: "",
2527
DisableTimestamp: false,
26-
DisableHTMLEscape: false,
28+
DisableHTMLEscape: true,
2729
DataKey: "",
2830
FieldMap: nil,
2931
CallerPrettyfier: nil,
@@ -56,7 +58,10 @@ func (s *streamHook) Fire(entry *logrus.Entry) error {
5658
return err
5759
}
5860

59-
s.server.Publish(LOGS, &sse.Event{Event: []byte(LOGS), Data: line})
61+
// remove "Line Feed"("\n") character which add was added by json.Encoder
62+
line = bytes.TrimRight(line, "\n")
63+
64+
s.server.Publish(Logs, &sse.Event{Event: []byte(Logs), Data: line})
6065
return nil
6166
}
6267

0 commit comments

Comments
 (0)