Skip to content

Commit

Permalink
Also use log format template when following logs
Browse files Browse the repository at this point in the history
  • Loading branch information
tikinang committed Aug 20, 2024
1 parent 3f9ad25 commit d1d3e32
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/serviceLogs/handler_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/gorilla/websocket"
"github.com/pkg/errors"

"github.com/zeropsio/zcli/src/i18n"
"github.com/zeropsio/zerops-go/types/uuid"
)
Expand All @@ -36,7 +37,7 @@ func (h *Handler) getLogStream(

done := make(chan interface{}) // Channel to indicate that the receiverHandler is done

go h.receiveHandler(conn, inputs.format, done)
go h.receiveHandler(conn, inputs.format, inputs.formatTemplate, done)

for {
select {
Expand Down Expand Up @@ -81,7 +82,7 @@ func (h *Handler) updateUri(uri, query string) string {
return WSS + uri + query + from
}

func (h *Handler) receiveHandler(connection *websocket.Conn, format string, done chan interface{}) {
func (h *Handler) receiveHandler(connection *websocket.Conn, format, formatTemplate string, done chan interface{}) {
defer close(done)

for {
Expand All @@ -100,17 +101,17 @@ func (h *Handler) receiveHandler(connection *websocket.Conn, format string, done
return
}

h.printStreamLog(msg, format)
h.printStreamLog(msg, format, formatTemplate)
}
}

func (h *Handler) printStreamLog(data []byte, format string) {
func (h *Handler) printStreamLog(data []byte, format, formatTemplate string) {
jsonData, _ := parseResponse(data)
// only if there is a new message coming
if len(jsonData.Items) > 0 {
// update last msg ID for ws reconnection
h.lastMsgId = jsonData.Items[len(jsonData.Items)-1].Id
err := parseResponseByFormat(jsonData, format, "", STREAM)
err := parseResponseByFormat(jsonData, format, formatTemplate, STREAM)
if err != nil {
fmt.Println(err.Error())
}
Expand Down

0 comments on commit d1d3e32

Please sign in to comment.