receive frontend logs using WS.

This commit is contained in:
Miroslav Šedivý 2021-09-09 22:08:39 +02:00
parent 83aa2dde41
commit afc79ed847
4 changed files with 32 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package event
const (
SYSTEM_INIT = "system/init"
SYSTEM_ADMIN = "system/admin"
SYSTEM_LOGS = "system/logs"
SYSTEM_DISCONNECT = "system/disconnect"
)

View File

@ -29,6 +29,14 @@ type SystemAdmin struct {
BroadcastStatus BroadcastStatus `json:"broadcast_status"`
}
type SystemLogs = []SystemLog
type SystemLog struct {
Level string `json:"level"`
Fields map[string]string `json:"fields"`
Message string `json:"message"`
}
type SystemDisconnect struct {
Message string `json:"message"`
}

View File

@ -41,6 +41,13 @@ func (h *MessageHandlerCtx) Message(session types.Session, data types.WebSocketM
var err error
switch data.Event {
// System Events
case event.SYSTEM_LOGS:
payload := &message.SystemLogs{}
err = utils.Unmarshal(payload, data.Payload, func() error {
return h.systemLogs(session, payload)
})
// Signal Events
case event.SIGNAL_REQUEST:
payload := &message.SignalVideo{}

View File

@ -3,6 +3,8 @@ package handler
import (
"errors"
"github.com/rs/zerolog"
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message"
@ -80,3 +82,17 @@ func (h *MessageHandlerCtx) systemAdmin(session types.Session) error {
return nil
}
func (h *MessageHandlerCtx) systemLogs(session types.Session, payload *message.SystemLogs) error {
for _, log := range *payload {
level, _ := zerolog.ParseLevel(log.Level)
h.logger.WithLevel(level).
Fields(log.Fields).
Str("session_id", session.ID()).
Str("service", "frontend").
Msg(log.Message)
}
return nil
}